Alick Dikan
Alick Dikan

Reputation: 65

Table View Did Select Row

So i have a tableView with checkmark accessory type and I have such method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger newRow = [lastIndexPath row];
    NSUInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;

    if (newRow != oldRow) {
        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;

        UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
        oldCell.accessoryType = UITableViewCellAccessoryNone;
        lastIndexPath = indexPath;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

And it seems to work fine for the first time, but when I select the row for the second time it throws me out and says EXC_BAD_ACCESS. and when I switch the simulator to 4.3, it selects the row only ones and then doesn't work. Can anybody help?

Upvotes: 0

Views: 12512

Answers (1)

phi
phi

Reputation: 10733

Use self.lastIndexPath = indexPath if you have a @property declared for lastIndexPAth.

Upvotes: 4

Related Questions