UIStoryboard name and bundle
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!
The name
parameter is the name of your .storyboard
file (without the extension).
The bundle
is usually the main bundle of your application. In general, you pass nil
so that the runtime will search your storyboard file in the main bundle by default (same as if you pass [NSBundle mainBundle]
). And in practice you generally only have one bundle in iOS applications, which is the main bundle representing your IPA bundle, so nil
is the common value for this parameter)
For example, if you have a storyboard named MyStory.storyboard
your would write:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStory" bundle:nil];
Actually all of this is explained in the Apple documentation for this method.
storyboardWithName:bundle:
Creates and returns a storyboard object for the specified storyboard resource file.
+ (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil
Parameters
name
: The name of the storyboard resource file without the filename extension. This method raises an exception if this parameter is nil.storyboardBundleOrNil
: The bundle containing the storyboard file and its related resources. If you specify nil, this method looks in the main bundle of the current application.