agro1986 agro1986 - 1 year ago 126
iOS Question

How does XCode load the main storyboard?

When I create a new single view application in XCode 4.6 using storyboard, we can see that the main function creates a new application using the application delegate like this:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));

However if we look at MyAppDelegate.h and MyAppDelegate.m, there is nowhere in the code that references MainStoryboard.storyboard. This differs from a non-storyboard version where we can find the line of code that loads the nib file programmatically.

So my question is, how does the storyboard get loaded? (where should I poke to find it?)


Answer Source

Look at your Target settings for the Project

enter image description here

Notice the Main Storyboard setting.

If you wanted to do this in code yourself, you would do something like.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

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

   // Set root view controller and make windows visible
   self.window.rootViewController = vc;
   [self.window makeKeyAndVisible];

   return YES;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download