我收到了一些使用Swift的錯誤,並且當我嘗試了其他Stack Overflow帖子中列出的解決方案時,我收到了其他錯誤。第一個錯誤我得到的是 NSForwarding:警告:類「h2.Items」不實現methodSignatureForSelector對象0x7dc4ca30: - 麻煩了 無法識別的選擇 - [h2.Items的initWithCoder:]爲什麼會有未捕獲的異常?
那麼我已經更新了我代碼添加「NSObject」,當我這樣做時,我得到以下錯誤:
終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:' - [h2.Items initWithCoder:]:無法識別的選擇器發送到實例0x79069250'
我不確定該從哪裏出發。我一直在下面的http://shrikar.com/blog/2015/01/17/uitableview-and-uitableviewcell-customization-in-swift/
沒有人有任何其他建議解決方法?
我的代碼是:
import CloudKit
import UIKit
import Foundation
class Items: NSObject
{
class Entry
{
var filename : String
init(fname : String)
{
self.filename = fname
}
}
var pics = [
Entry(fname: "circle.png")
]
}
這裏是正在調用類的代碼:
var items = Items()
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.pics.count
}
override func tableView(tableVIew: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TableViewCell
let entry = items.pics[indexPath.row]
let image = UIImage(named: entry.filename)
cell.anotherSelfie.image = image
return cell
}
}
,這裏是該小區的代碼:
class TableViewCell: UITableViewCell {
@IBOutlet var anotherSelfie: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
您應該顯示出現這些錯誤的代碼。 – 2015-02-05 18:20:39
這是針對Objective-C的,但它解釋了無法識別的選擇器異常:http://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error – 2015-02-05 18:23:41
您定義'Items'作爲符合'NSObject'協議的類,這並不意味着它是NSObject。事實上,你在'Items'定義中定義了另一個類型。 NSObjects不能在其定義中定義其他類...以及函數,結構體,枚舉。可能這是你問題的根源。 – 2015-02-05 18:58:10