【发布时间】: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 还是什么?这在网上没有很好的记录。有人可以建议吗?谢谢!
【问题讨论】: