表视图是否选择了行

时间:2011-11-29 15:45:49

标签: ios uitableview checkmark

所以我有一个带有checkmark附件类型的tableView,我有这样的方法:

- (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];
}

它似乎第一次正常工作,但是当我第二次选择该行时,它会抛弃我并说出EXC_BAD_ACCESS。当我将模拟器切换到4.3时,它只选择行,然后不起作用。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:4)

如果您为self.lastIndexPath = indexPath声明了@property,请使用lastIndexPAth

相关问题