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!
From the point of view of the UI designer, XIB files contain the views or windows that you design in Interface Builder – the controls, their layout and properties, and their connections to your code. It is important to understand that on a technical level, XIB files are stored object graphs.
yes , you can copy the the contents of the xib file by just (command+c) and paste it into another xib file by using (command +v) but by simply cop and pasting you won't get the references you need to go the properties in xib file there you need to give the class name for which you have created a new xib file and then ...
XIB files are in XML format to make them easier to use with version control systems and text-based tools. Let's go ahead and start using IB. To do this, first create an iOS App using the Single View Application iOS Project template in Xcode.
First of all if a bundle is not created properly it will not get loaded. So in-order to create a proper bundle below are the steps for creating a bundle:
Add a new target by choosing a template named bundle under OS X -> Framework & Libraries.
Select newly created target and change BaseSDK from OSX to Latest iOS.
Add .xibs, images or other resources which you want to use it from bundle in Build Phrases -> Copy Bundle Resources.
Add CoreFoundation framework in Build Phrases -> Link binary with Libraries.
Compile the target choosing iOS Device.
Save the newly created bundle from Products directory to some place.
Now copy that bundle into your main project. Load a bundle using below code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"BundleName" ofType:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:path];"
You are now set with the new bundle.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With