ios - 线程 1:在获取 TableView 的可重用单元格时发出 SIGABRT 信号
问题描述
背景
我试图重用一个名为“PhotoCell”的单元格,用于此提要中的不同提要。放置一些断点后,我的代码到达了从 PhotoCell 中获取 ReusableCell 的位置,并出现如下错误:
2019-10-24 10:17:45.962720-0700 Gallery[15203:376468]
*** Assertion failure in -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:],
/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3899.13.13/UITableView.m:8589
2019-10-24 10:17:45.978775-0700 Gallery[15203:376468] ***
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'unable to dequeue a cell with identifier EventFeedPhotoCell -
must register a nib or a class for the identifier
or connect a prototype cell in a storyboard'
所以我知道错误发生在哪里,但我不清楚如何通过打印语句等进行调试。我该如何解决这个问题?
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//Get a event feed photo cell
let cell = tableView.dequeueReusableCell(withIdentifier: Constants.Storyboard.eventFeedPhotoTableCell, for: indexPath) as! PhotoCell
//Get the photo for this row
let photo = photos[indexPath.row]
//Set the details for the cell
cell.setPhoto(photo)
return cell
}
解决方案
问题是您正在尝试将单元格出列,EventFeedPhotoCell
但您可能已将单元格重用标识符名称作为其他名称,请交叉检查单元格标识符名称。
推荐阅读
- electron - 我们可以将电子应用程序部署到dll吗?
- c++ - GDI Win32 绘图图
- tensorflow - Keras,tape.gradient 返回无值
- kubernetes - GridGain 服务器部署/Statefulset 终止宽限期
- powerbi - Power BI 形状图颜色饱和度不会呈现所有数据
- autodesk-forge - 应用了 BIM 360 API、PATCH 用户端点、与行业角色关联的服务
- git - 使用 ssh 密钥克隆存储库后,将“gitlab.com”(ED25519)永久添加到已知主机列表是什么意思
- ios - UIPhotoPickerController 选择按钮不起作用
- java - java.lang.BootstrapMethodError:来自调用站点#8 引导方法的异常
- javascript - 使用 MERN 添加复选框