Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

281
Vistas
Could not cast value of type 'UITableViewCell' to 'SwipeCellKit.SwipeTableViewCell'

I'm trying to use a pod called SwipeCellKit in my project, where this pod add a class called SwipeTableViewCell. What I have done so far is:

  • Create a view controller to the storyboard.
  • Create a UIViewController class.
  • Import SwipeCellKit to the Swift file.
  • Assign view controller to the class.
  • Add table view to the view controller.
  • Connect delegate and data source from table view to the view controller.
  • Add prototype cell to the table view, and named it "cell" for its reusable identifier.
  • Change the cell class into SwipeTableViewCell.
  • Add table view delegate to the view controller.
  • Add numberOfRows and cellForRow function to my UIViewController class.

This is the implementation of the cellForRow:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! SwipeTableViewCell;
    return cell;
}

But I got error on the let cell = ..., saying:

Could not cast value of type 'UITableViewCell' to 'SwipeCellKit.SwipeTableViewCell'

Why? And how to fix this? I think I have arranged everything as it should be. Did I miss something?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

What solved the problem for me:

In Main.Storyboard (or where you have your views), make sure that everywhere you want to use the reusable "cell", in the Identity Inspector on the right pane, you have the following:

  • Class is set to SwipeTableViewCell
  • Module is set to SwipeCellKit.
over 4 years ago · Santiago Trujillo Denunciar

0

You need to create your own Cell class as subclass of SwipeTableViewCell then you need to implement SwipeTableViewCellDelegate protocol in your ViewController

and for this line

let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! SwipeTableViewCell

you should use your class name which is a SwipeTableViewCell subclass

example

let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! MySwipeableCell
cell.delegate = self
over 4 years ago · Santiago Trujillo Denunciar

0

I created the following example

import UIKit
import SwipeCellKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {


    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! SwipeTableViewCell
        return cell
    }

}


class SwipeTableViewCellSubClass: SwipeTableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

}

set the class for your view to be SwipeTableViewCellSubClass.

this should work perfectly for you. good luck

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda