Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading a nib that's included in a Framework [duplicate]

Possible Duplicate:
Can you reference Xib files from static libraries on the iPhone?

I have created an iOS framework and it includes a xib view. When I debugged the program, this line of code worked fine:

MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyView" bundle:[NSBundle mainBundle]];

However, when I 'reference' the framework from another project - the nib is no longer in the 'mainBundle'. What should I do with the code above (that is part of the framework) so it loads from the framework and not the consuming application project?

like image 524
ConfusedNoob Avatar asked Sep 24 '12 01:09

ConfusedNoob


1 Answers

The framework in question should have a bundle identifier in its Info.plist file typically. In the application that makes use of this custom framework, you should be able to access resources in this bundle by:

NSString *frameworkBundleID = @"com.yourCompany.YourFrameworkBundleID";
NSBundle *frameworkBundle = [NSBundle bundleWithIdentifier:frameworkBundleID];

This is the NSBundle from which you can access framework resources.

EDIT:

There appears to be an alternate (possibly better) means of accessing the bundle in question.

e.g.:

NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"MyLibraryResources" withExtension:@"bundle"]];

See this excellent tutorial

like image 85
FluffulousChimp Avatar answered Sep 27 '22 23:09

FluffulousChimp