I get a crash as soon as I try to show a view from a bundle. Here's the setup:
- Project contains a bundle CFramework.bundle inside the app's main bundle
- CFramework.bundle contains GigyaFBPreviewController.xib and images it uses, in its root
- GigyaFBPreviewController.m is in a static library referenced by the project
Code:
NSString* bundlePath = [[NSBundle mainBundle] pathForResource:@"CBCFramework" ofType:@"bundle"];
NSBundle* bundle = [NSBundle bundleWithPath:bundlePath];
GigyaFBPreviewController* gigya = [[GigyaFBPreviewController alloc] initWithNibName:@"GigyaFBPreviewController" bundle:bundle];
[self presentModalViewController:gigya animated:YES];
The code is executed after a button click, and crashes on the last line. GigyaFBPreviewController is just a UIViewController, and it uses the default initWithNibName:bundle:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
'Could not load NIB in bundle: 'NSBundle </Users/mjovanovic/Library/Application Support/iPhone Simulator/4.3.2/Applications/A40F8D71-EB88-4EB5-B9D3-CFD330C57F24/socialmediatest.app/CBCFramework.bundle> (not yet loaded)' with name 'GigyaFBPreviewController''
*** Call stack at first throw:
(
0 CoreFoundation 0x01ad85a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01c2c313 objc_exception_throw + 44
2 CoreFoundation 0x01a90ef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x01a90e6a +[NSException raise:format:] + 58
4 UIKit 0x00e050fa -[UINib instantiateWithOwner:options:] + 2024
5 UIKit 0x00e06ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
6 UIKit 0x00cbc628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
7 UIKit 0x00cba134 -[UIViewController loadView] + 120
8 UIKit 0x00cba00e -[UIViewController view] + 56
9 UIKit 0x00cbba3d -[UIViewController viewControllerForRotation] + 63
10 UIKit 0x00cb7988 -[UIViewController _visibleView] + 90
11 UIKit 0x00f5993c -[UIClientRotationContext initWithClient:toOrientation:duration:andWindow:] + 354
12 UIKit 0x00c3181e -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 954
13 UIKit 0x00eb9619 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 1381
14 UIKit 0x00cbe65d -[UIViewController presentModalViewController:withTransition:] + 3478
15 socialmediatest 0x000027bb -[socialmediatestViewController clicky:] + 283
etc
Relevant info:
- If I take the nib file out of CFramework.bundle and put it into the project, it works fine. However, I need it in a bundle to distribute with a static library.
- The bundle exists inside the .app and calling [bundle pathForResource:@"GigyaFBPreviewController" ofType:@"xib"] returns the correct path.
- If I remove the image reference from the nib, nothing changes. All images are referenced as CFramework\image.png
- The "(not yet loaded)" error message is really weird. I found a bunch of posts with people running into the same exception when switching to Xcode4, but their solutions didn't work for me.
* SOLUTION *
The xib was not compiled into a nib and it could not be loaded, duh. Thank you Joshua Weinberg for providing the link below in the comments!