Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top