【发布时间】:2021-07-21 00:05:24
【问题描述】:
我正在创建一个非常简单的应用程序,当我尝试将我的 tableview 单元格出列时出现此错误。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "AnimalCell", for: indexPath) as! AnimalTableViewCell
let animal = animals[indexPath.row]
let thisLocation = locations.randomElement()
cell.fillInTheDetails(animal: animal, location: thisLocation!)
return cell
}
当我调用它时遇到错误
let cell = tableView.dequeueReusableCell(withIdentifier: "AnimalCell", for: indexPath) as! AnimalTableViewCell
报错信息如下:
TableViewWithMap[27537:9935669] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x600001224030> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key animalName.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff20422fba __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff20193ff5 objc_exception_throw + 48
2 CoreFoundation 0x00007fff20422c5b -[NSException init] + 0
3 Foundation 0x00007fff207af46c
我已经在 viewDidLoad 函数中注册了这个 TableViewcell
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "AnimalTableViewCell", bundle: nil), forCellReuseIdentifier: "AnimalCell")
【问题讨论】:
-
什么是“动物名”?
标签: swift uitableview