I have a UITableViewCell
that is selected when tapped. During this selected state, if the user taps the cell again, I want the cell to deselect.
I can\
Here is an even cleaner solution:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[tableView indexPathForSelectedRow] isEqual:indexPath]) {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
return nil;
}
return indexPath;
}
I think that using the blue selection colouring for toggling may give a strange impression. Why not use an accessory like a checkmark? This is a much more familiar technique for selection toggling (be it multi-cell or single-cell).
See this answer for info: UITableView Multiple Selection