从第三方库呈现故事板视图控制器
Present storyboard view controller from third party library
我已经使用 cocoapods 安装了第三方库,并试图在我的项目 viewDidLoad 中展示库中包含的故事板。我相信我下面的代码应该可以工作
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"library.storyboard" bundle:nil];
WrapperViewController *myVC = (WrapperViewController*) [storyboard instantiateViewControllerWithIdentifier:@"libraryStoryboard"];
[self presentViewController:myVC animated:YES completion:nil];
但是当我 运行 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序时,我收到此错误,原因:'无法在捆绑包 NSBundle 中找到名为 'library.storyboard' 的故事板。
知道为什么无法构建吗?
如果实际文件在包中命名为 library.storyboard
,那么在您的 storyboardWithName
方法中您将只写 library
。它还区分大小写,因此请确保您的名称正确无误。所以应该是storyboardWithName:@"library"
那个故事板在你的主包中吗?
- 名称参数是您的 .storyboard 文件的名称(不带扩展名)。
- 首先检查故事板是否位于您的主包中。如果不是,则将包名称从
更改为
From
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"library.storyboard" bundle:nil];
To
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"library" bundle:[NSBundle <name of bundle or mainbundle>]];
- 模拟器不区分大小写,但设备区分大小写。所以请检查名称是否正确
我已经使用 cocoapods 安装了第三方库,并试图在我的项目 viewDidLoad 中展示库中包含的故事板。我相信我下面的代码应该可以工作
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"library.storyboard" bundle:nil];
WrapperViewController *myVC = (WrapperViewController*) [storyboard instantiateViewControllerWithIdentifier:@"libraryStoryboard"];
[self presentViewController:myVC animated:YES completion:nil];
但是当我 运行 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序时,我收到此错误,原因:'无法在捆绑包 NSBundle 中找到名为 'library.storyboard' 的故事板。
知道为什么无法构建吗?
如果实际文件在包中命名为 library.storyboard
,那么在您的 storyboardWithName
方法中您将只写 library
。它还区分大小写,因此请确保您的名称正确无误。所以应该是storyboardWithName:@"library"
那个故事板在你的主包中吗?
- 名称参数是您的 .storyboard 文件的名称(不带扩展名)。
- 首先检查故事板是否位于您的主包中。如果不是,则将包名称从 更改为
From
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"library.storyboard" bundle:nil];
To
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"library" bundle:[NSBundle <name of bundle or mainbundle>]];
- 模拟器不区分大小写,但设备区分大小写。所以请检查名称是否正确