Use Storyboard from Resource Bundle File

bundle, ios, storyboard

Solution

You need to create a proper bundle, not just rename a directory with a `.bundle` extension.

Your resources such as the storyboard need to be in the `Contents/Resources/` subdirectory, and you need an `Info.plist` in the `Contents/` directory as well.

You can generate a basic template by creating a new target and picking Bundle from OS X > Framework & Library. Then archive it and look in the archive.

There's probably a more streamlined way of doing it with target dependencies, but it wasn't obvious to me how to make Xcode build the bundle with a normal build command, it only seems to work with archiving.

For more information, see Loadable Bundles in Apple's Bundle Programming Guide.

Problem

I created a bundle file and imported the bundle file into my project. There is a storyboard in this bundle file and I would like to create view from this storyboard. I have been trying to find out correct way to do this for 2 days, but got no luck. It always shows "'Could not find a storyboard named 'StoryboardA' in bundle NSBundle" error. I have a sample project here : https://github.com/tsunglintsai/Storyboard-In-Resource-Bundle. Following is code I tried. ``` NSBundle *resourceBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"bundlefilename" ofType:@"bundle"]]; [resourceBundle load]; NSLog(@"resourceBundle:%@",resourceBundle); UIStoryboard *sb = [UIStoryboard storyboardWithName:@"StoryboardA" bundle:resourceBundle]; UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"myViewController"]; vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentViewController:vc animated:YES completion:NULL]; ``` -- I can't find answer from following similar question posts: How to load storyboard file from custom bundle in IOS app? Xcode Copy Bundle Resources can't find files "Could not find a storyboard named 'MainStoryboard' in bundle NSBundle"

Original source

Related problems