How do I change “initwithNibName” in storyboard?

前端 未结 2 1117
天涯浪人
天涯浪人 2020-12-07 11:22

I want to change below code with storyboard with Xcode 4.2.

UIViewController * example     = [[ExampleViewController alloc] initWithNibName:@\"ExampleViewCon         


        
相关标签:
2条回答
  • 2020-12-07 11:52
    • If it is still in its own xib file, then you don't change anything.
    • If you've moved everything into a storyboard, then you wouldn't often need to do this as you'd link between view controllers using segues.

    If neither of the above are true, i.e. your view controller is on the storyboard but no segue connects to it, then you want UIStoryboard's instantiateViewControllerWithIdentifier: method described in the documentation. You have to set the identifier in the storyboard for this to work.

    0 讨论(0)
  • 2020-12-07 12:04

    The UIStoryboard class is your friend:

    UIStoryboard* sb = [UIStoryboard storyboardWithName:@"mystoryboard"
                                                  bundle:nil];
    UIViewController* vc = [sb instantiateViewControllerWithIdentifier:@"ExampleViewController"];
    
    0 讨论(0)
提交回复
热议问题