0
所以我有一个的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时,它只选择行,然后不起作用。任何人都可以帮忙吗?
lastIndexPath @property是怎么样的? – phi
@property(nonatomic,retain)NSIndexPath * lastIndexPath;像这样 –
如何声明lastIndexPath?我的猜测是这是问题。第一次通过lastIndexPath是零,所以没有问题。第二遍,它是一个指向已被释放的对象的指针(从先前调用didSelectRowAtIndexPath的indexPath)。 –