Programmatically navigate to another view controller/scene

后端 未结 19 3189
一向
一向 2020-11-27 11:29

I got an error message during navigating from first view controller to second view controller. My coding is like this one

let vc = LoginViewController(nibNam         


        
19条回答
  •  执笔经年
    2020-11-27 11:59

    You can move from one scene to another programmatically using below code :

      let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
    
      let objSomeViewController = storyBoard.instantiateViewControllerWithIdentifier(“storyboardID”) as! SomeViewController
    
      // If you want to push to new ViewController then use this
      self.navigationController?.pushViewController(objSomeViewController, animated: true)
    
      // ---- OR ----
    
      // If you want to present the new ViewController then use this
      self.presentViewController(objSomeViewController, animated:true, completion:nil) 
    

    Here storyBoardID is value that you set to scene using Interface Builder. This is shown below :

提交回复
热议问题