ios – 致命错误:无法创建捆绑包的路径

前端之家收集整理的这篇文章主要介绍了ios – 致命错误:无法创建捆绑包的路径前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直试图制作一个包含.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’DellStatusTable’,:git => ‘https://github.com/myname/OrderStatusTableView.git’,:tag => ‘1.2.0’到我的Podfile.我的.xib文件包含在示例项目的pod中的Resources文件夹中,但我不断收到此错误:致命错误:无法创建包的路径:file / Users / myname / Desktop / appname / OrderStatusTableDemo / Pods /OrderStatusTable/OrderStatusTable/OrderStatusTable.swift,第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或什么?这在网上没有很好的记录.有人可以建议吗?谢谢!

解决方法

在这里,您需要将其添加到您的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)

猜你在找的iOS相关文章