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

最初は問題なく動作しているように見えますが、2 回目に行を選択すると、EXC_BAD_ACCESS と表示されて終了します。シミュレーターを 4.3 に切り替えると、行のみが選択され、機能しません。誰でも助けることができますか?

4

1 に答える 1

4

self.lastIndexPath = indexPathに対して@propertyが宣言されている場合に使用しますlastIndexPAth

于 2011-11-29T15:50:27.277 に答える