简体   繁体   中英

Loading a storyboard from a framework

I'm creating a library with Cocoapods and 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`.

What I have tried:

  • put my storyboard inside the Classes folder
  • put my storyboard inside the Assets folder
  • Delete my application from the device, clean the project and re-build.
  • Use UIStoryboard(name:"Main", bundle:nil)
  • Use UIStoryboard(name:"Main", bundle:NSBundle(forClass:self))
  • Use 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. 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. Trying to load it as the initial view controller. After changing the settings, UIStoryboard(name:"Main", bundle:NSBundle(forClass:self) just works properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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