【问题标题】:XIB files in CocoapodCocoapod 中的 XIB 文件
【发布时间】:2018-05-10 12:27:53
【问题描述】:

我刚刚写了一个 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']
}

【问题讨论】:

    标签: ios objective-c cocoapods


    【解决方案1】:

    前段时间我也遇到过同样的问题。我通过使用特定类作为参考而不是 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)
    

    【讨论】:

      猜你喜欢
      • 2014-09-02
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      • 2019-06-25
      • 2011-07-20
      • 1970-01-01
      相关资源
      最近更新 更多