2016-09-20 16 views
0

我使用iphone Main.storyboard和第二一二故事板第一個是Main_iPad.storyboard,我想爲iPad和iPhone我使用這個代碼分別致電:如何在iOS中調用不同的Storyboard?

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil]; 
    EABaseRootVC *loginController = [storyboard instantiateViewControllerWithIdentifier:@"root2"]; 
    UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginController]; 
    self.window.rootViewController=navController; 
} 
else 
{ 

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    EABaseRootVC *loginController = [storyboard instantiateViewControllerWithIdentifier:@"root"]; 
    UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginController]; 
    self.window.rootViewController=navController; 
} 

但它始終顯示Main.storyboard iPhone資產。

我已經按照這個Different storyboards for iPhone and iPad in xcode 6

,如果您有任何其他想法,所以請給我建議。 我做錯了什麼?

回答

0

要識別蘋果設備而無論是iPhoneiPad使用下面的代碼:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
    // code for iPad 
}else{ 
    // code for iPhone 
} 

而且必須添加項目的.plist文件中這兩個鍵。

Main storyboard file base name (iPad) 
Main storyboard file base name (iPhone) 

見圖片:

enter image description here

+0

我已經在我的Info.plist文件,但工作不添加這些東西。 – AforAmit

+0

可能你已經在你的項目中更新了另一個plist文件,只需再次檢查它..這個代碼工作正常 – vaibhav

+0

是的,我知道這段代碼工作正常,但不是在我的最後確定讓我檢查。 – AforAmit

相關問題