Question

I started by building 2 versions of my app, on for 3.5 inch screens and one for 4 inch with only the storyboard being different. I brought the 3.5 storyboard into the 4 inch project and used the following code in my appDelegate.m to have the program run the appropriate storyboard.

UIViewController *vc;
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
{
    if ([[UIScreen mainScreen] bounds].size.height == 568.0f)
    {
        NSLog(@"IPHONE IS WORKING");
        UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil];
        vc = [storybord instantiateInitialViewController];
    }
    else
    {
        UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"MainFour.storyboard" bundle:nil];
        vc = [storybord instantiateInitialViewController];
    }
}
else
{
    UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
    vc = [storybord instantiateInitialViewController];
}
[_window setRootViewController:vc];
[_window makeKeyAndVisible];

When I use this, I get the error:

"Could not find a storyboard named 'Main.storyboard' in bundle NSBundle"

The error happens even if I try and use the storyboard that was not imported, the one that runs if the above code is missing. So I am assuming that the error lies in the name of the storyboard. In the project navigator, the storyboard is named "Main.storyboard" but calling that name does not find it. What am I doing wrong? Thanks.

Was it helpful?

Solution

Drop the .storyboard extension from the name you specify.

From the reference:

storyboardWithName:bundle:

Creates and returns a storyboard object for the specified storyboard resource file.

+ (UIStoryboard *)storyboardWithName:(NSString *)name
                              bundle:(NSBundle *)storyboardBundleOrNil

Parameters

name The name of the storyboard resource file without the filename extension. This method raises an exception if this parameter is nil.

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