【发布时间】:2012-01-18 21:56:13
【问题描述】:
当我尝试显示捆绑包中的视图时,我会立即崩溃。这是设置:
- 项目在应用的主包中包含一个包 CFramework.bundle
- CFramework.bundle 在其根目录中包含 GigyaFBPreviewController.xib 和它使用的图像
- GigyaFBPreviewController.m 位于项目引用的静态库中
代码:
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];
代码在单击按钮后执行,并在最后一行崩溃。 GigyaFBPreviewController 只是一个 UIViewController,它使用默认的 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
相关信息:
- 如果我将 nib 文件从 CFramework.bundle 中取出并放入项目中,它可以正常工作。但是,我需要将它打包成一个静态库分发。
- bundle 存在于 .app 中,调用 [bundle pathForResource:@"GigyaFBPreviewController" ofType:@"xib"] 返回正确的路径。
- 如果我从笔尖中删除图像参考,则没有任何变化。所有图片都被引用为 CFramework\image.png
- “(尚未加载)”错误消息真的很奇怪。我发现很多帖子有人在切换到 Xcode4 时遇到了同样的异常,但他们的解决方案对我不起作用。
* 解决方案 *
xib 没有编译成 nib 并且无法加载,呵呵。感谢 Joshua Weinberg 在 cmets 中提供以下链接!
【问题讨论】:
-
(not yet loaded)不一定是错误消息。这只是意味着您尚未向该捆绑包发送load消息。 -
异常描述是什么?
-
它在设备上运行时如何编译?
-
解决方法见第一条评论。
标签: ios xcode4.2 bundle nib ios5