2016-08-18 39 views
4

我一直在试图制作一个CocoaPod,其中包含.xib整整两天,无济于事。我有一个独立的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文件包含在示例项目荚内的资源文件夹,但我不断收到此错误: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笔尖与小区复用标识,像这样:

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或什么?这在网上没有很好的记录。有人可以请指教吗?谢谢!

回答

0

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