0

I am trying to load different storyboard but am getting this error Application windows are expected to have a root view controller at the end of application launch. Can anyone help me out

- (UIStoryboard *)grabStoryboard {

    UIStoryboard *storyboard;

    // detect the height of our screen
    int height = [UIScreen mainScreen].bounds.size.height;

    if (height == 480) {
        storyboard = [UIStoryboard storyboardWithName:@"iPhone_4" bundle:nil];
        // NSLog(@"Device has a 3.5inch Display.");
    }
    if(height == 568)
    {
        storyboard = [UIStoryboard storyboardWithName:@"iPhone_5" bundle:nil];
        // NSLog(@"Device has a 4inch Display.");
    }
    if(height == 667)
    {
        storyboard = [UIStoryboard storyboardWithName:@"iPhone_6" bundle:nil];
        // NSLog(@"Device has a 4inch Display.");
    }

    if(height == 736)
    {
        storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        // NSLog(@"Device has a 4inch Display.");
    }

    return storyboard;
}
MedAmine.Rihane
  • 1,193
  • 10
  • 17
Eunice
  • 1
  • The error almost certainly lies in your applicationdidfinishlaunching function inside of your appdelegate. Post that as well – chedabob May 19 '15 at 17:33
  • As a side note, there really shouldn't be a reason for you to load a different storyboard for each iPhone screen size. Auto-layout and size classes can handle that in a much more elegant and manageable way... – Yann Bodson Aug 16 '16 at 22:44

2 Answers2

0

You are getting this error because compiler see the case when your function can return uninitialised storyboard variable. It might happened if non of the if statements is true. So it's better to rewrite this function so it always return initialised storyboard variable. My suggestion is to change the way how to determine device model. Take a look at this post for hint.

Community
  • 1
  • 1
salabaha
  • 2,468
  • 1
  • 17
  • 18
0

i think one or more of your storyboards doesn't have an entry point make sure to verify them all . you can check the official doc here entry point for storyboard

MedAmine.Rihane
  • 1,193
  • 10
  • 17