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
How to Integrate Linphone into an Existing Project (Sip in iOS)
Clean Architecture - Robert Martin - How to Connect Use Cases
Reading Firebase Auth Error Thrown (Firebase 3.X and Swift)
iOS - Detect Blow into Mic and Convert the Results! (Swift)
Ios- How to Integrate Push Notification in iOS 10
Uitableview:Viewforheaderinsection: Not Called During Reloaddata:
How to Get Enum from Raw Value in Swift
Could Not Instantiate Class Named Ibnslayoutconstraint
Ios11 Wkwebview Crash Due to Nsinvalidunarchiveoperationexception
iOS Facebook Sdk 4.0 Login Error Code 304
Cellforitematindexpath Not Called But Numberofitemsinsection Does
Storyboard Uiviewcontroller, 'Custom Class' Not Showing in Drop Down
Nsdictionaryofvariablebindings Swift Equivalent
How to Remove All Gesture Recognizers from a Uiview in Swift
How to Get the Status Bar Height in iOS 13
Swift: Get All Subviews of a Specific Type and Add to an Array