我刚写了一个cocoapod并发表了它。在本地,它适用于该示例。
但是,当我尝试通过“pod install”安装并使用它时,它在加载XIB文件时出现问题。
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle:
我目前正在加载XIB文件,如下所示:
NSString* const frameworkBundleID = @"org.cocoapods.MyPod";
NSBundle *podBundle =[NSBundle bundleWithIdentifier:frameworkBundleID];
早些时候我也试过(下面)也在本地工作。
NSBundle *podBundle = [NSBundle bundleForClass:[self class]];
我可能做错了什么使它在本地工作但在发布后却没有?
仅供参考,以下是规范的外观:
s.source_files = 'Pod/Classes/**/*.{h,m}'
s.resource_bundles = {
'NetLogger' => ['Pod/Assets/*.xcassets', 'Pod/Classes/*.xib']
}
答案 0 :(得分:0)
我前一段时间遇到过同样的问题。我使用特定的类作为参考而不是self
来修复它:
NSBundle *podBundle = [NSBundle bundleForClass:[ClassIncludedInPod class]];
例如加载MyViewController
我会使用:
NSBundle *bundle = [Bundle bundleForClass:[MyViewController class]];
MyViewController *myVC = [[MyViewController alloc] initWithNibName:@"MyViewController"
bundle:bundle];
这里是Swift:
let bundle = Bundle(for: MyViewController.self)
let myVC = MyViewController(nibName: "MyViewController", bundle: bundle)