我有一个 View (不是 View Controller ),当我按下按钮时会弹出。
在此 View 中,我有一个 UIButton
和一个 UITableView
。我想使用我在 xib 文件中设计的 UITableViewCell
。
所以我创建了我的细胞类:
class PickerViewCell: UITableViewCell {
@IBOutlet weak var flagImageView: UIImageView!
@IBOutlet weak var codeLabel: UILabel!
@IBOutlet weak var nameLabel: UILabel!
func setCell(myObject: myObject) {
flagImageView.image = UIImage(named: myObject.code)
codeLabel.text = myObject.code
codeLabel.font = myObject.kPickerViewCodeFont
nameLabel.text = myObject.name
nameLabel.font = myObject.kPickerViewNameFont
}
}
我的 xib 文件:
这里我没有设置 xib 的所有者(我也尝试过),我为 UITableViewCell
添加了自定义类,并且没有重用标识符(我也尝试过)。
在我的 View (包含 TableView 的 View )的 init 函数中,我执行以下操作:
let nib = UINib(nibName: "PickerViewCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "cell")
最后我实现了该方法:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! PickerViewCell
let myObject = myObjects[indexPath.row]
cell.setCell(myObject)
return cell
}
当我想显示(创建)我的 View 时,调试器停止在
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! PickerViewCell
我收到以下错误:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x7f9b934d8c70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key codeLabel.'
出了什么问题?
编辑:
最佳答案
检查 @IBOutlet weak var codeLabel: UILabel!
与 PickerViewCell
中 IB 的连接。尝试重新连接。
关于ios - 从 View 中的 UITableView 中的 xib 文件加载 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33667050/