Cast Value of Type 'Uitableviewcell' to Custom Cell

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

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

UITableView - Could not cast value of type 'UITableViewCell' to AppName.CustomCell

You need to change your code so that the cell class you're registering is actually being used in your cellForRow method. Try this:

func viewDidLoad() {
tableView.register(NameTableViewCell.self, forCellReuseIdentifier: "cellName")
tableView.register(OtherTableViewCell.self, forCellReuseIdentifier: "otherName")
tableView.register(ThirdTableViewCell.self, forCellReuseIdentifier: "thirdName")
}

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

if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellName", for: indexPath) as! NameTableViewCell
// your cell setup code here
return cell
} else if indexPath.row == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "otherName", for: indexPath) as! OtherTableViewCell
return cell
} else if indexPath.row == 2 {
let cell = tableView.dequeueReusableCell(withIdentifier: "thirdName", for: indexPath) as! ThirdTableViewCell
return cell
}
}

Could not cast value of type 'UITableViewCell' to 'AppName.CustomCellName'

"I have self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "eventCell") in my viewDidLoad"

That's probably overriding the value you set in the storyboard. Try removing this line, or change it to self.tableView.registerClass(EventTableViewCell.self, forCellReuseIdentifier: "eventCell").

Could not cast value of type 'UITableViewCell' to 'NSIndexPath' in Swift

You cannot send indexPath as a sender parameter. The sender: is the UI element that triggered the segue, which in this case is a UITableViewCell.
So, you send the tableViewCell instance in the sender like:

guard let cell = tableView.cellForRowAt(indexPath: indexPath) else {return}
//alternatively
//let cell = tableView.cellForRowAt(indexPath: indexPath)!
performSegue(withIdentifier: "toDetails", sender: cell)


Related Topics



Leave a reply



Submit