2015-05-19 65 views
0

我想加载不同的故事板,但我得到这个错误应用程序窗口预计在应用程序启动结束时有一个根视图控制器。任何人都可以帮助我加载不同的故事板导致错误

- (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; 
} 
+0

这个错误几乎肯定存在于你的appdelegate中的applicationdidfinishlaunching函数中。发布以及 – chedabob

+0

作为一个方面说明,真的不应该有一个理由为你的每个iPhone屏幕尺寸加载一个不同的故事板。自动布局和大小类可以以更加优雅和可管理的方式处理... –

回答

0

你会得到这个错误,因为编译器会看到你的函数可以返回未初始化的故事板变量的情况。如果if语句不为真,可能会发生这种情况。所以最好重写这个函数,以便它总是返回初始化的storyboard变量。我的建议是改变如何确定设备型号的方式。看看这个post提示。

0

我认为你的一个或多个故事板没有入口点,请务必对其进行验证。你可以在这里查看官方文档entry point for storyboard