【问题标题】:fatal error: Could not create a path to the bundle致命错误:无法创建包的路径
【发布时间】:2016-08-18 05:37:36
【问题描述】:

整整两天我一直在尝试制作一个包含.xib 的 CocoaPod,但无济于事。我的框架有一个独立的 Xcode 项目,带有以下.podspec

Pod::Spec.new do |s|
  s.name         = "OrderStatusTable"
  s.version      = "1.2.0"
  s.platform = :ios
  s.ios.deployment_target = '9.0'
  s.summary      = "Order Status UITableView framework."
  s.description  = "A UITableView framework with custom view."
  s.homepage     = "https://github.com/myname/OrderStatusTableView"
  s.license = { :type => "MIT", :file => "LICENSE" }
  s.author = { "My Name" => "My Email" }
  s.platform     = :ios, "9.0"
  s.source       = { :git => "https://github.com/myname/OrderStatusTableView.git", :tag => "1.2.0" }

  s.source_files = "OrderStatusTable/**/*.{h,m,swift}"

  s.resource_bundles = {
    'OrderStatusTable' => [
        'Pod/**/*.xib'
    ]
  }

end

在我的示例项目中,我将pod 'OrderStatusTable', :git => 'https://github.com/myname/OrderStatusTableView.git', :tag => ‘1.2.0’ 添加到我的 Podfile 中。我的 .xib 文件包含在示例项目的 pod 内的 Resources 文件夹中,但我不断收到此错误:fatal error: Could not create a path to the bundle: file /Users/myname/Desktop/appname/OrderStatusTableDemo/Pods/OrderStatusTable/OrderStatusTable/OrderStatusTable.swift, line 40

这是一个UITableView 框架,我正在尝试使用单元重用标识符注册一个自定义UITableViewCell nib,如下所示:

    public class OrderStatusTable: UITableView {

    public override func awakeFromNib() {

        delegate = self
        dataSource = self

        let podBundle = NSBundle(forClass: self.classForCoder)

        if let bundleURL = podBundle.URLForResource("OrderStatusTable", withExtension: "bundle") {

            if let bundle = NSBundle(URL: bundleURL) {

                let cellNib = UINib(nibName: "OrderStatusTableViewCell", bundle: bundle)

                registerNib(cellNib, forCellReuseIdentifier: "OrderStatusTableViewCell")

            } else {

                assertionFailure("Could not load the bundle")

            }

        } else {

            assertionFailure("Could not create a path to the bundle")
            // This keeps getting called
        }
}

所以我不确定我是否有错误的捆绑包URLForResource 还是什么?这在网上没有很好的记录。有人可以建议吗?谢谢!

【问题讨论】:

    标签: ios swift git cocoapods


    【解决方案1】:

    在这里,您需要将其添加到您的 pod 规范中。

     s.resources = "YourProjectName/*.xib"
     s.resource_bundles = {
       'YourProjectName' => [
           'Pod/**/*.xib'
       ]
     }
    

    对于这个特定的问题,

    s.resources = "OrderStatusTable/*.xib"
     s.resource_bundles = {
       'OrderStatusTable' => [
           'Pod/**/*.xib'
       ]
     }
    

    那么你的代码有错误。

    不要使用

     let podBundle = Bundle(for: self.classForCoder)
    

    而不是像这样使用这个:-

    let podBundle = Bundle(for:YourClassName.self)
    

    对于这个问题,应该是

     let podBundle = Bundle(OrderStatusTable.self)
    

    【讨论】:

      猜你喜欢
      • 2015-05-10
      • 1970-01-01
      • 1970-01-01
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      相关资源
      最近更新 更多