following code starts with a blank cells and add a checkmark when selected cell but, once added, if you press again that cell, it is not erased. I am trying to reset it each time that didSelectRowAtIndexPath is called. How to clear cell in order to be marked only one? Thanks.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryNone;
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0:
labelInfo.text=@"1";
cell.accessoryType = UITableViewCellAccessoryCheckmark;
break;
case 1:
labelInfo.text=@"2";
cell.accessoryType = UITableViewCellAccessoryCheckmark;
break;
case 2:
labelInfo.text=@"3";
cell.accessoryType = UITableViewCellAccessoryCheckmark;
break;
case 3:
labelInfo.text=@"4";
cell.accessoryType = UITableViewCellAccessoryCheckmark;
break;
case 4:
labelInfo.text=@"5";
cell.accessoryType = UITableViewCellAccessoryCheckmark;
break;
default:
break;
}
}
}
Just copy-paste this. It works.