If you select the cell with checkmark, this code will be executed.
if(self.checkedIndexPath)
{
UITableViewCell* uncheckCell = [tableView
cellForRowAtIndexPath:self.checkedIndexPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
This code will remove the checkmark which you have added during the first select.
then this code will be executed
if([self.checkedIndexPath isEqual:indexPath])
{
self.checkedIndexPath = nil;
}
Thus only when you select the same cell again, the checkmark will reappear
I think the cleaner way will be as followed.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cellCheck = [tableView
cellForRowAtIndexPath:indexPath];
cellCheck.accessoryType = UITableViewCellAccessoryCheckmark;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* uncheckCell = [tableView
cellForRowAtIndexPath:indexPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
AS you can get the value for self.checkedIndexPath from [tableView indexPathForSelectedRow]; the setting of self.checkedIndexPath is optional depending on the logic of your code.