Dev*_*shi 11 cocoa-touch objective-c xib ios ios7
我正在尝试通过遵循此URL中指定的步骤为iOS创建通用框架:Universal-framework-iOS
我有一个viewController类,该框架内部加载.xib文件.
下面是代码的一部分,它显示了我如何初始化viewController并显示相关视图:
/*** Part of implementation of SomeViewController class, which is outside the framework ***/
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.viewControllerWithinFramework = [[ViewControllerWithinFramework alloc] initWithTitle:@"My custom view"];
}
- (IBAction)showSomeView:(id)sender {
[self.viewControllerWithinFramework showRelatedView];
}
/*** Part of implementation of ViewControllerWithinFramework class, which is inside the framework ***/
- (id)initWithTitle:(NSString *)aTitle
{
self = [super initWithNibName:@"ViewControllerWithinFramework" bundle:nil]; // ViewControllerWithinFramework.xib is within the framework
if (self)
{
_viewControllerTitle = aTitle;
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
在创建框架时,我在其Copy Bundle Resources构建阶段包含了所有.xib文件,包括ViewControllerWithinFramework.xib .
现在我的问题是,当我尝试将该框架集成到其他项目中时,它崩溃了下面的堆栈跟踪:
Sample[3616:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/miraaj/Library/Application Support/iPhone Simulator/7.0/Applications/78CB9BC5-0FCE-40FC-8BCB-721EBA031296/Sample.app> (loaded)' with name 'ViewControllerWithinFramework''
*** First throw call stack:
(
0 CoreFoundation 0x017365e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014b98b6 objc_exception_throw + 44
2 CoreFoundation 0x017363bb +[NSException raise:format:] + 139
3 UIKit 0x004cc65c -[UINib instantiateWithOwner:options:] + 951
4 UIKit 0x0033ec95 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
5 UIKit 0x0033f43d -[UIViewController loadView] + 302
6 UIKit 0x0033f73e -[UIViewController loadViewIfRequired] + 78
7 UIKit 0x0033fc44 -[UIViewController view] + 35
Run Code Online (Sandbox Code Playgroud)
任何想法,我怎么能解决这个问题?
注意:如果框架中没有任何xib,它可以正常工作.
XIB 附带的框架通常也附带捆绑包 - 因此您可能不应该在框架部分传递 nil 。
右键单击框架 -> 在查找器中显示 打开它并查看资源文件夹中的包名称是什么(例如 - Facebook 使用 FBUserSettingsViewResources.bundle)并使用它。
一般来说 - 静态库不包含 xib 或资源文件。框架基本上是静态库、标头和一些资源(通常在捆绑包内)的包装器