2015-05-19 77 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