简体   繁体   English

从框架加载情节提要

[英]Loading a storyboard from a framework

I'm creating a library with Cocoapods and Swift 1.2. 我正在用Cocoapods和Swift 1.2创建一个库。 I have a storyboard that I have to load in my library. 我有一个故事板,必须将其加载到库中。 Although, I am always getting this same error: 虽然,我总是会遇到同样的错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main' in bundle`. 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'在捆绑包中找不到名为'Main'的故事板。

What I have tried: 我尝试过的

  • put my storyboard inside the Classes folder 将我的情节提要放在Classes文件夹中
  • put my storyboard inside the Assets folder 将我的故事板放在Assets文件夹中
  • Delete my application from the device, clean the project and re-build. 从设备中删除我的应用程序,清理项目并重新生成。
  • Use UIStoryboard(name:"Main", bundle:nil) 使用UIStoryboard(name:"Main", bundle:nil)
  • Use UIStoryboard(name:"Main", bundle:NSBundle(forClass:self)) 使用UIStoryboard(name:"Main", bundle:NSBundle(forClass:self))
  • Use UIStoryboard(name:"Main", identifier:myIdentifier) 使用UIStoryboard(name:"Main", identifier:myIdentifier)

I was although able to load the storyboard from my example project, put then I was only able to instantiate the initial view controller. 尽管我能够从示例项目中加载情节提要,但那时我只能实例化初始视图控制器。

Trying to invoke storyboard!.instantiateViewControllerWithIdentifier(someIdentifier) from the initial view controller always resulted in the view controller not being found, although I can clearly see that there is a view controller with that identifier. 尝试从初始视图控制器调用storyboard!.instantiateViewControllerWithIdentifier(someIdentifier)总是导致找不到视图控制器,尽管我可以清楚地看到有一个带有该标识符的视图控制器。 How can I fix this issue? 如何解决此问题?

Found the problem. 找到了问题。 Just silly but after deleting the Main.storyboard from the project, I didn't remove it from the project's settings. 只是很傻,但是在从项目中删除Main.storyboard之后,我没有从项目的设置中将其删除。 Trying to load it as the initial view controller. 尝试将其加载为初始视图控制器。 After changing the settings, UIStoryboard(name:"Main", bundle:NSBundle(forClass:self) just works properly. 更改设置后, UIStoryboard(name:"Main", bundle:NSBundle(forClass:self)可以正常工作。

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

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