I'm currently following along with a guide (creating custom tableview cells in swift) to create a custom cell for a UITableView in Swift. However, I'm having an error when I run the project. Below is the code where the error is triggered:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// ***** Error triggers on the line below ******
let cell:MyCustomCellModel = self.plantList.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as! MyCustomCellModel
cell.plantImage.backgroundColor = self.colors[indexPath.row]
cell.plantLabel.text = self.animals[indexPath.row]
return cell
}
My issue is identical to ones described in other stackoverflow posts (namely: Could not cast value of type 'UITableViewCell' to '(AppName).(CustomCellName)'), however none of the solutions therein were able to fix my problem.
Here are the various attempts I've made to fix the problem.
Checked that the cell has the correct class and identifier. I checked this first, and below are two relevant screenshots.
I have tried both of the below code solutions to register my class(which I put into the viewdidload method), with neither providing a fix:
self.plantList.register(MyCustomCellModel.self, forCellReuseIdentifier: "cell") self.plantList.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
I have also tried many of the little fixes that worked for people mentioned in the various stackoverflow posts on this issue, but none of them have worked for me.
Any tips would be greatly appreciated. If any other source code is needed to debug this, I will gladly post it.