【发布时间】:2017-02-24 00:34:08
【问题描述】:
当我的“else”块的第一行运行时,我收到了这个错误:
无法将带有标识符 PhoneCell 的单元格出列 - 必须为标识符注册一个 nib 或一个类,或者在情节提要中连接一个原型单元格
所以,初始表加载得很好,但是当您尝试进行搜索时,会抛出此异常。这只是在我进入自定义单元后才开始发生。这是崩溃表的 cellForRowAtIndexPath 函数。知道发生了什么吗?
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == self.tableView{
let cell = self.tableView.dequeueReusableCell(withIdentifier: "PhoneCell", for: indexPath) as! PhoneSearchResultTableViewCell
cell.nameLabel.text = phones[indexPath.row].name.value
cell.descriptionLabel.text = phones[indexPath.row].descriptionText.value
cell.modelLabel.text = phones[indexPath.row].model.value
return cell
}else{
let cell = self.resultsController.tableView.dequeueReusableCell(withIdentifier: "PhoneCell", for: indexPath) as! PhoneSearchResultTableViewCell
cell.nameLabel.text = filteredPhones[indexPath.row].name.value
cell.descriptionLabel.text = filteredPhones[indexPath.row].descriptionText.value
cell.modelLabel.text = filteredPhones[indexPath.row].model.value
return cell
}
}
【问题讨论】:
-
您是否在 resultsController 中的表格视图中注册了“PhoneCell”标识符?
标签: swift uitableview uisearchdisplaycontroller