【发布时间】:2015-04-25 07:27:31
【问题描述】:
在我的项目中,我有不同的 Storyboard 文件来支持不同的 iPhone,我的 appDelegate 中有这段代码:
if (window.frame.size.height == 568){
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:kMain5Name bundle:[NSBundle mainBundle]];
id rootViewController = [storyBoard instantiateInitialViewController];
[window setRootViewController:rootViewController];
} else if (window.frame.size.height == 480){
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:kMain5Name bundle:[NSBundle mainBundle]];
id rootViewController = [storyBoard instantiateInitialViewController];
[window setRootViewController:rootViewController];
} else if (window.frame.size.height == 667){
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:kMain6Name bundle:[NSBundle mainBundle]];
id rootViewController = [storyBoard instantiateInitialViewController];
[window setRootViewController:rootViewController];
} else if (window.frame.size.height == 736){
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:kMain6plusName bundle:[NSBundle mainBundle]];
id rootViewController = [storyBoard instantiateInitialViewController];
[window setRootViewController:rootViewController];
}
每次我编译和运行应用程序崩溃时说它在 NSBundle 中找不到故事板文件,我把上面的代码注释掉了,它又可以工作了。我的代码有问题吗?
【问题讨论】:
-
你为什么不给我们看名字,然后用那些故事板展示项目导航器的截图?如果它说找不到他们..那么也许你有一两个错误的名字。
-
同上,我们需要知道
kMain5Name是否真的在您的项目中。该错误表明它或它的同伴不在您的项目中。 -
有些相关,您可能想简单地使用自动布局和尺寸类来处理不同的设备尺寸。你不使用这些工具有什么原因吗?
-
@RodericCampbell 我从以前的项目(针对 iOS 7)中获取了代码,由于某种原因,我不记得我在以前的项目中禁用了自动布局,所以我在这个项目中做了(大小类自动布局时会自动禁用)kMain5Name 是带有文件名的宏(#define)。
-
@EarlGrey 我有确切的名称(我将文件名复制并粘贴到宏中(#define)。我还不能发布图片(低声誉)
标签: ios storyboard xcode6 nsbundle