Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIStoryboard name and bundle

Tags:

xcode

ios

I have this line of code:

[UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)];

and a storyboard file. Where do I actually insert the name of the controller, and where do I find the bundle?

It is a stupid question, but I can't figure it out

like image 566
Alessandro Avatar asked Sep 21 '12 15:09

Alessandro


1 Answers

Everything is really straightforward!

This is the code:

UIStoryboard *storyboard = 
[UIStoryboard storyboardWithName:@"MainStoryboard" 
                          bundle:[NSBundle mainBundle]];

Where is @"Main Storyboard" is the name of your .storyboard file. Bundle is just the bundle that contains your .storyboard file, usually is the main bundle of your app.

If you want to get access to some of the UIViewControllers, for example, with the purpose of pushing it to the stack of your UINavigationController, then you must do this:

UIViewController *yourViewController = 
[storyboard instantiateViewControllerWithIdentifier:@"viewControllerIdentifier"];

You can set Identifier to your UIViewController in the Xcode's Identity Inspector!

Hope it helps you!

like image 169
Anatoliy Gatt Avatar answered Sep 17 '22 17:09

Anatoliy Gatt