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\
You can actually do this using the delegate method willSelectRowAtIndexPath:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isSelected]) {
// Deselect manually.
[tableView.delegate tableView:tableView willDeselectRowAtIndexPath:indexPath];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView.delegate tableView:tableView didDeselectRowAtIndexPath:indexPath];
return nil;
}
return indexPath;
}
Note that deselectRowAtIndexPath:
won't call the delegate methods automatically, so you need to make those calls manually.