swift presentViewController programmatically finds nil in destinationVC VDL

后端 未结 1 1471
予麋鹿
予麋鹿 2021-01-17 02:10

Trying to solidify my knowledge by understanding lines of code at a basic level.

I\'ve tweaked my app to use ViewController(VC)2 as initial VC instead of VC1.

相关标签:
1条回答
  • 2021-01-17 02:35

    So when instantiating a VC (storyboard-created), first we need to route our call through the UIStoryboard by name

    let storyboard = UIStoryboard(name: "Main", bundle: nil)  
    

    then instantiate a VC using the Storyboard ID of our storyboard setup VC

    let vc = storyboard.instantiateViewControllerWithIdentifier("VC1") as VC1    //VC1 refers to destinationVC source file and "VC1" refers to destinationVC Storyboard ID
    

    Then we can present VC using

    self.presentViewController(vc, animated: true, completion: nil)
    

    This will import all of destinationVC's objects with their IBOutlet references.

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