Programmatically navigate to another view controller/scene

后端 未结 19 3014
一向
一向 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)
    
    0 讨论(0)
  • 2020-11-27 11:55
    let VC1 = self.storyboard!.instantiateViewController(withIdentifier: "MyCustomViewController") as! ViewController
    let navController = UINavigationController(rootViewController: VC1)
    self.present(navController, animated:true, completion: nil)
    
    0 讨论(0)
  • 2020-11-27 11:56

    I think you are looking for something like this:

    let signUpViewController = SignUpViewController()
    present(signUpViewController, animated: true, completion: nil)
    

    If you want full screen of the new page:

    present(signUpViewController, animated: true, completion: nil)
    

    Hope this helps :)

    0 讨论(0)
  • 2020-11-27 11:57

    Try this one. Here "LoginViewController" is the storyboardID specified in storyboard.

    See below

    let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("LoginViewController") as LoginViewController
    self.navigationController?.pushViewController(secondViewController, animated: true)
    
    0 讨论(0)
  • 2020-11-27 11:57

    XCODE 8.2 AND SWIFT 3.0

    Present an exist UIViewController

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

    Push an exist UIViewController

    let loginVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
    self.navigationController?.pushViewController(loginVC, animated: true)
    

    Remember that you can put the UIViewController Identifier following the next steps:

    • Select Main.storyboard
    • Select your UIViewController
    • Search the Utilities in the right
    • Select the identity inspector
    • Search in section identity "Storyboard ID"
    • Put the Identifier for your UIViewController

    0 讨论(0)
  • 2020-11-27 11:58

    See mine.

    func actioncall () {
        let loginPageView = self.storyboard?.instantiateViewControllerWithIdentifier("LoginPageID") as! ViewController
        self.navigationController?.pushViewController(loginPageView, animated: true)
    }
    

    If you use presenting style, you might lose the page's navigation bar with preset pushnavigation.

    0 讨论(0)
提交回复
热议问题