0

When I load my UITableViewController that populates with custom (xib) cells, my app crashes with error: Could not cast value of type 'SwipeCellKit.SwipeTableViewCell' to 'GreenHarvestAlpha.ListCell'. Yet, ListCell has the grandparent class SwipeTableViewCell.

If I don't downcast, class ListViewController won't connect to the custom cell (and I get buildtime errors that my custom cell's properties don't exist).

Custom cell

class ListCell: SwipeTableViewCell {

Swipe class (dequeues cell)

`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
}

List class (crashes with downcast error):

class ListViewController: SwipeVC

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

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

Also, I'm already overriding prototype cells in another class and this process is working for that.

eyesplice17
  • 231
  • 2
  • 6

0 Answers0