Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

280
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda