ios - 添加第二个 Storyboard会导致 "could not find storyboard"错误

标签 ios objective-c xcode storyboard

我开始构建我的应用程序的 2 个版本,一个用于 3.5 英寸屏幕,一个用于 4 英寸屏幕,只有 Storyboard不同。我将 3.5 Storyboard带入 4 英寸项目,并在我的 appDelegate.m 中使用以下代码让程序运行适当的 Storyboard。

UIViewController *vc;
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
{
    if ([[UIScreen mainScreen] bounds].size.height == 568.0f)
    {
        NSLog(@"IPHONE IS WORKING");
        UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil];
        vc = [storybord instantiateInitialViewController];
    }
    else
    {
        UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"MainFour.storyboard" bundle:nil];
        vc = [storybord instantiateInitialViewController];
    }
}
else
{
    UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
    vc = [storybord instantiateInitialViewController];
}
[_window setRootViewController:vc];
[_window makeKeyAndVisible];

当我使用它时,我收到错误:

"Could not find a storyboard named 'Main.storyboard' in bundle NSBundle"



即使我尝试使用未导入的 Storyboard ,也会发生错误,如果缺少上述代码, Storyboard 会运行。所以我假设错误在于 Storyboard 的名称。在项目导航器中, Storyboard被命名为 "Main.storyboard"但是调用那个名字并没有找到它。我究竟做错了什么?谢谢。

最佳答案

放弃.storyboard您指定的名称的扩展名。

来自 reference :

storyboardWithName:bundle:

Creates and returns a storyboard object for the specified storyboard resource file.

+ (UIStoryboard *)storyboardWithName:(NSString *)name
                              bundle:(NSBundle *)storyboardBundleOrNil

Parameters

name The name of the storyboard resource file without the filename extension. This method raises an exception if this parameter is nil.

关于ios - 添加第二个 Storyboard会导致 "could not find storyboard"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23368103/

相关文章:

ios - CALayer mask 会更新设备旋转

ios - iPhone 未在 Xcode Organizer 中列出

ios - 将 UIColors 保存和检索到核心数据的最佳方法

ios - 用户授权位置使用时的双重 segue 行为

objective-c - NSSharingService:如何与常量进行比较?

objective-c - 如何解决 EXC_BAD_ACCESS (SIGSEGV) 上的 KERN_INVALID_ADDRESS

ios - 自引用快速关闭

iOS ScrollView 需要约束 y 位置或高度

ios - 如何修复此“Pods.xcodeproj”?

ios - Swift3 警告 imagePickerController 几乎匹配