How do I change "initwithNibName" in storyboard?

IosXcodeStoryboardXib

Ios Problem Overview


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

UIViewController * example     = [[ExampleViewController alloc] initWithNibName:@"ExampleViewController" bundle:nil];

Now ExampleViewController.xib file exist. but I want to make it with storyboard. please help me. (I'm not good at English. Sorry)

Ios Solutions


Solution 1 - Ios

The UIStoryboard class is your friend:

UIStoryboard* sb = [UIStoryboard storyboardWithName:@"mystoryboard"
                                              bundle:nil];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:@"ExampleViewController"];

Solution 2 - Ios

  • 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjokor7View Question on Stackoverflow
Solution 1 - IosStephen DarlingtonView Answer on Stackoverflow
Solution 2 - IosjrturtonView Answer on Stackoverflow