Present View Controller in Storyboard with a Navigation Controller - Swift

后端 未结 5 1311
眼角桃花
眼角桃花 2021-01-30 10:30

I am currently showing a viewController in my new storyboard below:

var storyboard : UIStoryboard = UIStoryboard(name: AccountStoryboard, bundle: nil)
var vc : W         


        
5条回答
  •  终归单人心
    2021-01-30 11:26

    The answer given by @Chris is works good in older version of swift.

    Update Swift 3 & Swift 4

       let storyboard : UIStoryboard = UIStoryboard(name: "AccountStoryboard", bundle: nil)
       let vc : WelcomeViewController = storyboard.instantiateViewController(withIdentifier: "WelcomeID") as! WelcomeViewController
       vc.teststring = "hello"
    
       let navigationController = UINavigationController(rootViewController: vc)
    
       self.present(navigationController, animated: true, completion: nil)
    

    Thanks!!!

提交回复
热议问题