kstenerud / iOS-Universal-Framework

An XCode project template to build universal frameworks (arm7, arm7s, and simulator) for iOS / iPhone.
2.94k stars 471 forks source link

How to access resources? .xib / images / etc.. #84

Open omarojo opened 12 years ago

omarojo commented 12 years ago

Im having trouble how to load a View that is made in my framework and loaded in my app.

using the initwithNibName: bundle:

What should I put in bundle ?? how would it be to access images or other kind os resource ?

Screenshot My app: https://www.box.com/s/5a018452be0f7a2c10af

Screenshot My Framework: https://www.box.com/s/dfb9e3cdec2d810c130b

kstenerud commented 12 years ago

It should include the resources in the default bundle, so you can just use nil.

omarojo commented 12 years ago

Hows that ?? I think the .xib file is in the Bundle. check out the screenshot Screenshot My Framework: https://www.box.com/s/dfb9e3cdec2d810c130b

Where is the default bundle ?

kstenerud commented 12 years ago

TestViewController.nib is inside the "Resources" directory in MesquiteFW.embeddedframework.

Xcode sees TestViewController.nib as it sees any other resource, and places it at the top level of the "default" bundle, also known as the main bundle or application bundle. See here: https://developer.apple.com/library/mac/#documentation/CoreFOundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW13

This means that you load it exactly the same way as you'd load it if it were created inside your app project:

[[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil]
omarojo commented 12 years ago

So that means I have things well configured. well "bundle:nil" isnt working.

I get "signal SIGABRT" error https://www.box.com/s/e7a66d83d3f9f478d817

Thats why I asked.. cause I dont know why isnt working.

kstenerud commented 12 years ago

I've created an example framework and app project to demonstrate here: https://github.com/kstenerud/iOS-Universal-Framework/tree/examples/nib-in-framework

omarojo commented 12 years ago

I see.. your project works well. But I cant replicate it. I drag and drop my MesquiteFW.embeddedframework to my project. But resources dont get to top level.

This was the only way I could load the view.

NSString settingsPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"MesquiteFW.embeddedframework"]; NSBundle mibundle = [[NSBundle alloc] initWithPath:settingsPath];

TestViewController *nuevaVista = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:mibundle]; self.window.rootViewController = nuevaVista;

but Thanks anyways.

kstenerud commented 12 years ago

Make sure when you copy your framework in that you have the following selected:

omarojo commented 12 years ago

Thank you very much ! it worked out... have a coffee. :)