簡體   English   中英

如何在multiStoryBoard Universal App中為iPhone和iPad使用相同的故事板名稱?

[英]How to have same storyboard name for iPhone & iPad in multiStoryBoard Universal App?

我正在創建一個多情節提要應用程序。 根據要求,我在不同情況下使用不同的故事板。 為了支持所有設備,我必須編寫如下代碼:

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
   UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"blah_iPhone" bundle:nil];
   self.window.rootViewController = [storyboard instantiateInitialViewController];
}
else
{         
  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"blah_iPad" bundle:nil];
  self.window.rootViewController = [storyboard instantiateInitialViewController];
}
[self.window makeKeyAndVisible];

我也嘗試過使用代字號(〜),將情節blah~iphone命名為blah〜iphone和blah~ipad但它會引發如下錯誤:

2014-01-21 17:05:44.941 test[2709:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/3D8EC72E-D20D-4C60-A413-E8040A455262/blah.app> (loaded)' with name 'UIViewController-aYh-JW-qLA' and directory 'blah.storyboardc''
*** First throw call stack:
(0x2d4edf4b 0x37c846af 0x2d4ede8d 0x2ffbfe39 0x3010c03d 0x40ff5 0x2fcd12ff 0x2fcd0d4f 0x2fccb353 0x2fc6641f 0x2fc65721 0x2fccab3d 0x3211670d 0x321162f7 0x2d4b89df 0x2d4b897b 0x2d4b714f 0x2d421c27 0x2d421a0b 0x2fcc9dd9 0x2fcc5049 0x4134d 0x3818cab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

任何想法??

也許我缺少了一些東西,但是我不明白為什么如果使用情節提要文件,為什么要手動管理窗口。

我認為您正在為現有項目添加通用支持。 因為如果您創建一個新的通用應用程序,那么一切都會如您所願。

您需要在application:didFinishLaunchingWithOptions:程序委托中使用application:didFinishLaunchingWithOptions:方法,如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}

並且您的目標設置應如下所示,注意iPhone / iPad開關並為每個設備選擇不同的故事板。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM