Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

pushviewcontroller swift autolayout

//call in ViewdidLoad or in Button as
button.addTarget(self, action: #selector(backButtonAction), for: .touchUpInside)
button.addTarget(self, action: #selector(nextButtonAction), for: .touchUpInside)


//Next button Action
@objc func nextButtonAction(){
        let vc2 = SecondViewController()
        self.navigationController?.pushViewController(vc2, animated: true)
    }
//back button action
@objc func backButtonAction(){
        self.navigationController?.popViewController(animated: true)
    }

//if you are not using Storyboard
//also Verify in SceneDelegate 
var window: UIWindow?//verify
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = (scene as? UIWindowScene) else { return }
      
      
      let navController = UINavigationController(rootViewController: FirstViewController())
        navController.setNavigationBarHidden(true, animated: true)
        
        window = UIWindow(frame: windowScene.coordinateSpace.bounds)
        window?.makeKeyAndVisible()
        window?.windowScene = windowScene
        window?.rootViewController = navController
	}
 
PREVIOUS NEXT
Tagged: #pushviewcontroller #swift #autolayout
ADD COMMENT
Topic
Name
4+3 =