Estoy tratando de usar un pod llamado SwipeCellKit en mi proyecto, donde este pod agrega una clase llamada SwipeTableViewCell. Lo que he hecho hasta ahora es:
UIViewController .SwipeCellKit al archivo Swift.numberOfRows y cellForRow a mi clase UIViewController. Esta es la implementación de cellForRow :
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! SwipeTableViewCell; return cell; } Pero recibí un error en let cell = ... , diciendo:
No se pudo convertir el valor del tipo 'UITableViewCell' a 'SwipeCellKit.SwipeTableViewCell'
¿Por qué? ¿Y cómo arreglar esto? Creo que lo he arreglado todo como debe ser. ¿Me he perdido algo?
Lo que resolvió el problema para mí:
En Main.Storyboard (o donde tenga sus vistas), asegúrese de que en todos los lugares donde quiera usar la "celda" reutilizable, en el Inspector de identidad en el panel derecho, tenga lo siguiente:
Debe crear su propia clase de celda como subclase de SwipeTableViewCell , luego debe implementar el protocolo SwipeTableViewCellDelegate en su ViewController
y por esta linea
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! SwipeTableViewCell debe usar el nombre de su clase, que es una subclase SwipeTableViewCell
ejemplo
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! MySwipeableCell cell.delegate = selfCreé el siguiente ejemplo
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 } }establezca la clase para que su vista sea SwipeTableViewCellSubClass.
esto debería funcionar perfectamente para usted. buena suerte