4

I'm wondering if someone could explain (or point me in the right direction)

  1. where the code for instantiating UIWindow disappears to when NOT using storyboards? In the empty-application project template the window is created in application didFinishLaunnching... in your AppDelegate.

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    

    However if using storyboards, the above code is omitted, though obviously UIApplication knows which window to start off with.

  2. Where the application looks for the info.plist file to know which storyboard(s) to start off with.

I'm certain this is all well documented somewhere I just haven't found it. Read this Where is the UIWindow instantiated in an iPhone app? but not much help. I've been at iOS for awhile, just never had to mess with the initial startup of an app until now. Thanks

Community
  • 1
  • 1
Patrick Borkowicz
  • 1,206
  • 10
  • 19

2 Answers2

8

I think you meant 'where the code disappears to when you are using storyboards.'

The application loads the storyboard according to the "Main storyboard file base name" (UIMainStoryboardFile) key in your Info.plist, and from that storyboard it loads the view controller with the "Is initial view controller" toggle set.

Edit: As asked in the comments, the following code (similar to the initial loading in xib-based apps) will allow you to load and display a storyboard by name upon application launch:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardName" bundle:nil];
    UIViewController *viewController = [storyboard instantiateInitialViewController];
    self.window.rootViewController = viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
ttarik
  • 3,824
  • 1
  • 32
  • 51
  • I'll rephrase, how would I programatically change the initial storyboard at runtime? If I create an empty, non-storyboard app, I can add storyboards by 1. creating one, 2. adding the key to Info.plist, then 3. removing the window allocation code in appDelegate.. But how would I assign a different storyboard based on whatever when the app loads? – Patrick Borkowicz Oct 16 '12 at 18:40
  • That's the sort of thing you should be doing within your view controllers, what reason do you have for wanting to conditionally load different storyboards when the app launches? Regardless, I spent some time and managed to figure out how to do this, I have edited the question accordingly. – ttarik Oct 18 '12 at 07:07
0

While using storyboards, the storyboard to be loaded comes from your app's Info.plist file.

There will be a section in your Info.plist file with the key value pair like this:

<key>UIMainStoryboardFile</key>
    <string>MainStoryboard</string>

In this case, MainStoryboard is the name of the default storyboard that is loaded.

Bijoy Thangaraj
  • 5,434
  • 4
  • 43
  • 70