agro1986 agro1986 - 4 months ago 18
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?)



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;