1

選択したセルのリロードに問題があります。チュートリアルに従おうとしていますが、奇妙な問題で立ち往生しています。アイテムを選択するとチェックマークが表示/削除されると思われるリストを作成しました。ただし、リスト内の別のセルを選択するまで、セルは更新されません。

何か案は?

関連するソースコードを以下に添付しました。

ありがとう、K

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ListPrototypeCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    XYZToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;

if(toDoItem.completed) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
    cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
XYZToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
toDoItem.completed = !toDoItem.completed;
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
4

2 に答える 2

4

didDeselectRowAtIndexPathの代わりに誤って実装してしまいましたdidSelectRowAtIndexPath

于 2013-11-09T01:12:39.143 に答える
2

あなたの問題は、あなたが使用しなかったことですdidSelectRowAtIndexPathが、didDeselectRowAtIndexPath今はセルの選択を解除するたびにセルを更新します:)

于 2013-11-09T02:37:53.423 に答える