首页 > 解决方案 > 使用覆盖将 SwipeCellKit 连接到自定义单元格 - Swift

问题描述

当我加载填充自定义(xib)单元格的 UITableViewController 时,我的应用程序崩溃并出现错误: 无法将类型“SwipeCellKit.SwipeTableViewCell”的值转换为“GreenHarvestAlpha.ListCell”。 然而,ListCell有祖父母班SwipeTableViewCell

如果我不向下转换,类ListViewController将不会连接到自定义单元(并且我会收到我的自定义单元的属性不存在的构建时错误)。

自定义单元格

class ListCell: SwipeTableViewCell {

滑动类 (出列单元格)

`class SwipeVC: UITableViewController, SwipeTableViewCellDelegate {

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: K.cellSwipeIdentifier, for: indexPath) as! SwipeTableViewCell
    cell.delegate = self    
    return cell     }

func updateModel(at indexPath: IndexPath) {
    //leave empty. override in CategoryVC & ListVC with delete from realm functionality
}

列表类崩溃并出现向下错误):

class ListViewController: SwipeVC

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = super.tableView(tableView, cellForRowAt: indexPath) as! ListCell
    

另外,我已经在另一个类中覆盖了原型单元,这个过程正在为此工作。

标签: swiftxibcustom-celldowncast

解决方案


推荐阅读