I am using a table view and has a label in its cell. The thing I want is to change the cell label on every tap of a cell. I know that switch statement doesn’t work on indexPath. I want my cases 1 and 2 to work.
Here is my code:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
switch Value {
case 1:
cell.cellLabel.text = "first time label changes"
case 2:
cell.cellLabel.text = "second time label changes"
default:
cell.cellLabel.text = "change the label"
}
}
Does anyone have a solution that if I tap a cell first time case 1 should work and if I tap it again case 2 should work?
2
Answers
if you need "first" when you touch it 3 times
if you need multiple selection write
tableView.allowMultipleSelection = true