Custom init of UIViewController from storyboard

后端 未结 3 1103
被撕碎了的回忆
被撕碎了的回忆 2020-12-29 05:52

I tried finding some relevant questions but couldn\'t get anything, hope someone can help.

I set up some UIViewController\'s on a storyboard. I then want to load one

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 06:07

    An (ugly) way to solve this issue:

    You can set your let i from an external buffer in your code (AppDelegate variable in this example)

    required init?(coder aDecoder: NSCoder) {
        self.i = UIApplication.shared().delegate.bufferForI
    
        super.init(coder: aDecoder)
    }
    

    And when you initiate your UIViewController through Storyboard:

    UIApplication.shared().delegate.bufferForI = myIValue
    self.navigationController!.pushViewControllerFading(self.storyboard!.instantiateViewController(withIdentifier: "myViewControllerID") as UIViewController)
    

    EDIT: You don't have to pass the value through the AppDelegate. Better answer here.

提交回复
热议问题