这个类不是密钥值编码兼容的密钥...为什么? [英] This class is not key value coding-compliant for the key...why?
问题描述
我已将IB的输出链接到代码,如下所示。
I've linked output from the IB to the code, as shown below.
class DiaryTableViewCell: UITableViewCell {
@IBOutlet weak var TitleLabel: UILabel!
@IBOutlet weak var SubTitleLabel: UILabel!
@IBOutlet weak var leftImageView: UIImageView!
@IBOutlet weak var rightImageView: UIImageView!
}
在这里,我正在注册课程:
Here, I'm registering the class:
override func viewDidLoad() {
self.title = "My Diary"
cellNib = UINib(nibName: "TableViewCells", bundle: nil)
tableView.registerClass(DiaryTableViewCell.classForCoder(), forCellReuseIdentifier: kCellIdentifier)
}
但是我一直收到以下运行时错误:
But I keep getting the following runtime error:
***由于未捕获的异常'NSUnknownKeyException'终止应用程序,原因:'... setValue:forUndefinedKey:]:这个类不是键值
,对于键SubTitleLabel符合编码。'
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '...setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key SubTitleLabel.'
在以下代码中:
From within the following code:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as DiaryTableViewCell?
if (cell == nil) {
tableView.registerClass(DiaryTableViewCell.classForCoder(), forCellReuseIdentifier: kCellIdentifier)
cell = cellNib?.instantiateWithOwner(self, options: nil)[0] as? DiaryTableViewCell
cell?.selectionStyle = .None
}
if (cell != nil) {
println("\(x++)) Inside cell")
cell!.TitleLabel.text = "Hello"
cell!.SubTitleLabel.text = "World"
}
return cell!
}
具体来说,它发生在这里:
Specifically, it's happening here:
cell = cellNib?.instantiateWithOwner(self, options: nil)[0] as? DiaryTableViewCell
问题:我如何违反UILabel的密钥值是否符合编码?
之前没有发生过... UILabel符合KVO。
Question: How am I violating the key value coding-compliant for a UILabel?
This hasn't happened before... UILabel is KVO compliant.
推荐答案
我链接到错误的来源!
结果如下:
Here's the result:
这篇关于这个类不是密钥值编码兼容的密钥...为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!