views:

134

answers:

2

Hi there,

I'm having some trouble working with libraries and included xib files. Let me explain my situation first. I've got a project that's running pretty good. Now I need a part of my project as a library for another customer who want's to use some of the functionality in his app. I've created a library with help of that highly recommended article.

My customer should be able to initialize a main view controller like this:

LibraryMainViewController *lmvc = [[LibraryMainViewController alloc] initWithNibName:@"LibraryMainViewController.xib" bundle:foo];

That for sure leads to an error when I try to present that view controller modally. I'm not sure what bundle I have to use here. I tried something like

[NSBundle bundleForClass:[SomeClassInTheLibrary class]];

but that didn't solve the problem.

I would be glad if someone could tell me how to actually use a xib file in that kind of situation.

Thanks
–f

Update

Ok, I see I got it wrong somehow. Just for clarification: What I need is the library, the headers and the additional resources, right? Is there some kind of best practice for creating and shipping "a feature" with all it's parts above mentioned?

A: 

Try without adding the extension to the XIB file. That's the way i usually do it. I'm also not sure if the XIB must be compiled to a NIB..

NSBundle *bundle = [NSBundle bundleForClass:[SomeClassInTheLibrary class]];
LibraryMainViewController *lmvc = [[LibraryMainViewController alloc] initWithNibName:@"LibraryMainViewController" bundle:bundle];
stigi
When I try that I'm still getting an error saying 2010-05-09 12:18:23.099 test[6416:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] was unable to load a nib named "LibraryMainViewController"'Is it possible that I didn't add the xib file to that library correctly? I added it to the "Copy Bundle Resources Build Phase".
flohei
+2  A: 

Static libraries can't include graphics, sounds, xibs or even headers. Only object code. Even if you added the xibs to Copy Bundle Resources, they won't become a part of the object file. Unfortunately, you can't use dynamic libraries or frameworks on the iPhone. See my answer here for a suggestion of how to create a separate assets bundle. You could also just send your customer the xib files separately, but then they have to replace them by hand if they change in the future.

Felixyz
So if I did it this way I had to hand my customer the library, the headers and the bundle with the xib files, right?
flohei
Yes exactly. That's the way Facebook does it for example. (You can follow the link in the question I linked to.)
Felixyz