iOS - UITableViewCell在我选择另一个单元格之前不会重新加载

时间:2013-11-09 01:08:32

标签: ios objective-c uitableview

我在重新加载所选单元格时遇到问题。 试图按照教程但现在遇到一个奇怪的问题。 我已经列出了一个列表,其中选择一个项目是为了显示/删除复选标记。 但是,在我选择列表中的另一个单元格之前,单元格不会更新。

有什么想法吗?

我已在下面附上相关的源代码。

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

2 个答案:

答案 0 :(得分:4)

您不小心实施了didDeselectRowAtIndexPath而不是didSelectRowAtIndexPath

答案 1 :(得分:2)

你的问题是你没有使用didSelectRowAtIndexPath而是使用didDeselectRowAtIndexPath所以每次你取消选择你的​​单元格时你都会更新你的单元格:)