2016-08-18 78 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)