iOS - loading xib from bundle in Documents directory

bundle, ios

Solution

Following the instructions here works:

loading NSBundle files on iOS

I was just creating the bundle incorrectly!

You need to create the bundle in Xcode though because if you don't, it won't be loaded. To create, Add a New Target to your project, choose Framework & Library -> Bundle, and link to Core Foundation. Then add the xibs you want to upload to the web to the target. Build target, reveal it in Finder, compress, and upload!

Problem

I've been working on getting "custom skinnable" interfaces working for my iOS app by bundling up xibs and downloading bundles, and loading the xibs in those bundles. I have followed the very useful instructions here to get it almost working. loading NSBundle files on iOS I have the bundle downloading, and unzipping and can see the xib file. I have not used any of the TestViewController code in the example, but am instead doing this when creating the view controller using the just downloaded xib: ``` NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"gg.bundle"]; NSBundle *bundle = [NSBundle bundleWithPath:filePath]; if ( !bundle ) { NSLog(@"Error getting bundle"); } MyViewController *vc = [MyViewController new]; [vc initWithNibName:@"CustomDownloadedXib" bundle:bundle]; ``` When I go to push this view controller onto my stack, I get this error: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (not yet loaded)' with name 'CustomDownloadedXib'' The issue seems to be that my bundle is "not yet loaded." I tried forcing my bundle to load by calling: ``` [bundle load] ``` but that doesn't help. Is my approach here incorrect? This seems like the intuitive way to do it. Thanks in advance!

Original source

Related problems