我开始构建我的应用程序的 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/