2014-11-23 152 views
2

我創建了5個額外的故事板,並刪除了主要故事板。這是因爲我想爲iPhone和iPad配備5個獨立的故事板,以匹配5種不同的屏幕尺寸。到目前爲止,我有一個iPhone 3.5英寸,一個iPhone 4英寸,一個iPhone 4.7英寸,一個iPhone 5.5英寸和一個iPad。我已經將代碼放在了下面,將它們鏈接起來並使其工作。但是,當您嘗試構建項目時,它不起作用。沒有錯誤,但可以說我進入iPhone 3.5英寸的故事板,並添加一個UIViewController和一個Button或標籤,然後當您構建項目時,它會進入您的啓動屏幕,然後它不會從那裏做任何事情。我已經將啓動箭頭放在UIViewController中,但除了啓動屏幕之外,我無法獲得任何東西。我已經在所有的故事板和他們的模擬器上嘗試過。我想知道我是否在代碼中遺漏了某些東西,但我不確定。在Xcode中使用多個故事板

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
UIStoryboard *storyboard = nil; 
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPad) { 
    storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPad" bundle:nil];//iPad 
} else { 
    CGSize screenSize = [[UIScreen mainScreen] bounds].size; 
    if (screenSize.height == 480){ 
     storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4S" bundle:nil];//iPhone 3.5inch 
    } else 
     if (screenSize.height == 568){ 
      storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone5/5C/5S" bundle:nil];//iPhone 4inch 
     } 
     else 
     { if (screenSize.height == 667){ 
      storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone6" bundle:nil];//iPhone 4.7inch 
      } else 
       if (screenSize.height == 736){ 
        storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone6Plus" bundle:nil];//iPhone 5.5inch 
       } else 
        //default storyboard 
       storyboard = [UIStoryboard storyboardWithName:@"Main.Storyboard" bundle:nil]; 
      } 
} 
    self.window.rootViewController = [storyboard instantiateInitialViewController]; 
    [self.window makeKeyAndVisible]; 

return YES; 
} 

回答

3

在您的項目中找到您的info.plist文件並刪除名爲「Main storyboard file base name」的行。 enter image description here

此外,您忘了創建窗口(積分rdelmar)。

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

我強烈建議你看看Auto LayoutSize Classes。使用這兩個,你可以在一個Storyboard中支持所有的屏幕尺寸。一開始就有點難,但從長遠來看這絕對值得。

有一個來自最近的WWDC調用的視頻Building Adaptive Apps with UIKit

+0

謝謝你。但現在它只是進入黑屏而不是我的UIViewController,它有一個標籤說你好。其他尺寸也會發生同樣的情況。 – 2014-11-23 06:55:29

+1

您也可以通過單擊該項目並轉到常規窗格執行此操作。在那裏,只需刪除主界面字段中的「Main」。 – rdelmar 2014-11-23 06:56:11

+1

@BenjaminMcIntyre,你也需要創建窗口。 self.window將在你的代碼中爲零。 – rdelmar 2014-11-23 06:57:01