简体   繁体   English

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

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

I am creating a multiple storyboard app. 我正在创建一个多情节提要应用程序。 On basis of requirement, I am using different story board at different instances. 根据要求,我在不同情况下使用不同的故事板。 for supporting it all devices, I have to write my code like this: 为了支持所有设备,我必须编写如下代码:

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];

I've tried using tilde (~) also, naming the storyboard like blah~iphone & blah~ipad but it is throwing error like this: 我也尝试过使用代字号(〜),将情节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

Any idea?? 任何想法??

Maybe I'm missing something but I don't understand why you are managing the window manually if you are using storyboard files. 也许我缺少了一些东西,但是我不明白为什么如果使用情节提要文件,为什么要手动管理窗口。

I think you are adding universal support to an already existing project. 我认为您正在为现有项目添加通用支持。 Because if you create a new universal app everything will be just as you needed. 因为如果您创建一个新的通用应用程序,那么一切都会如您所愿。

You need your application:didFinishLaunchingWithOptions: method in your app delegate like this: 您需要在application:didFinishLaunchingWithOptions:程序委托中使用application:didFinishLaunchingWithOptions:方法,如下所示:

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

And your target settings should look like this, notice the iPhone / iPad switch and select different storyboards for each device. 并且您的目标设置应如下所示,注意iPhone / iPad开关并为每个设备选择不同的故事板。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM