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 try this one, it's works for me (for single selection or multiple selections):
A. allocate a private NSMutableArray in viewDidLoad like:
@interface XXXViewController : UIViewController
{
NSMutableArray * selectedZoneCellIndexPaths;
}
- (void)viewDidLoad
{
selectedZoneCellIndexPaths = [[NSMutableArray alloc] init];
}
B. in UITableViewDelegate didSelectRow add following lines
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
for (NSIndexPath * iter in selectedZoneCellIndexPaths)
{
if (indexPath.section == iter.section && indexPath.row == iter.row)
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[selectedZoneCellIndexPaths removeObject:iter];
return;
}
}
[selectedZoneCellIndexPaths addObject:indexPath];
return;
}