Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is UIWindow instantiated and the storyboard passed in?

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

like image 640
Patrick Borkowicz Avatar asked Feb 19 '23 20:02

Patrick Borkowicz


1 Answers

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;
}
like image 190
ttarik Avatar answered Mar 04 '23 00:03

ttarik