Programmatically navigate to another view controller/scene

后端 未结 19 3237
一向
一向 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:55

    If you want to navigate to Controller created Programmatically, then do this:

    let newViewController = NewViewController()
    self.navigationController?.pushViewController(newViewController, animated: true)
    

    If you want to navigate to Controller on StoryBoard with Identifier "newViewController", then do this:

    let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let newViewController = storyBoard.instantiateViewController(withIdentifier: "newViewController") as! NewViewController
            self.present(newViewController, animated: true, completion: nil)
    

提交回复
热议问题