首页 > 解决方案 > 线程 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

}

标签: iosswiftuitableview

解决方案


问题是您正在尝试将单元格出列,EventFeedPhotoCell但您可能已将单元格重用标识符名称作为其他名称,请交叉检查单元格标识符名称。


推荐阅读