Search code examples
objective-ciosuitableviewnsindexpath

didSelectRowAtIndexPath: how to get old indexPath to deselect checkmark?


How to deselect previously selected row in tableView ?? I can't find solution to obtain oldIndexPath

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
    if (newCell.accessoryType == UITableViewCellAccessoryNone) {
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;
    }  
}

Solution

  • Unless you store the previous index path, you won't be able to retrieve it.
    Just store it in an ivar, when you detect a row is selected, the next time you will be able to remove the checkmark on the previous cell.