Question

I wish to create an app with multiple storyboards to support iPhone5, iPhone4 (and below) and iPad screens.

I did the following:

  1. I created 3 storyboards, one per each setting.
  2. I cleared the "main storyboard" field in the project interface.
  3. I cleared the "Main storyboard file base name" field in the app info.plist file.
  4. I entered the following code to the AppDelegate "didFinishLaunchingWithOptions" method:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {        
    
        UIStoryboard* appStoryboard = nil;
    
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
        {
            if (IS_IPHONE_5) //a macro capturing the screen size
            {
                appStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5" bundle:nil];
            }
            else 
            {
                appStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone4" bundle:nil];
            }
        }
        else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
        {
            appStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
        }
        UIViewController* viewController = [appStoryboard instantiateInitialViewController];
        [self.window setRootViewController:viewController];
        [self.window makeKeyAndVisible];
        return YES;
    }
    

The application is running and not crashing, but I get a black screen.

What am I missing / doing wrong?

Was it helpful?

Solution

You didn't initialize the window.

Just add

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top