I want to change the image of the last cell if the user click on a new cell. For now im doing this:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//Old Cell Image
let lastCell = tableView.cellForRow(at: self.lastCell) as! DataTableViewCell!;
lastCell?.imageButton.image = UIImage(named: "RadioButtomDeactive.png")
let indexPathCel = tableView.indexPathForSelectedRow;
let currentCell = tableView.cellForRow(at: indexPathCel!) as! DataTableViewCell!;
dateSelected = currentCell?.dateSession.text
currentCell?.imageButton.image = UIImage(named: "RadioButtom.png")
}
I tried to save the indexPath.row in lastCell (that is an int) but it didn't work since cellForRow only accept indexPath.
You can simply create an IndexPath using your stored lastCell via:
IndexPath(row: self.lastCell, section: 0)
If there is more than one section, you'll just need to insert your last section instead of 0.
Why don't you keep in memory the IndexPath instead of an Int ?
or
you can create an IndexPath from your Int with
IndexPath(row: Int, section: Int)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With