2

我有一个包含自定义单元格的简单表格,每个单元格都包含一个文本字段。在cellForRowAtIndexPath:我根据indexPath.row创建和初始化每个单元格:

case 0:
{
    CellIdentifier = @"TextEditCell";
    TextEditCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
        cell = [topLevelObjects objectAtIndex:0];
    }

    [cell configureCellWithText: [self.valueArray objectAtIndex:0]
                    placeholder: @"value no.0"]

    [cell performAction: @selector(saveValue0:)
        forControlEvent: UIControlEventEditingDidEnd
               inTarget: self];

    return cell;
}

configureCellWithText:placeholder:设置单元格文本字段的文本和占位符。 performAction:forControlEvent:inTarget直接引用 textField 并将 textField 的值保存到本地数组中,以便再次使用时准确。

当我快速滚动表格时出现问题。来自不同单元格的值复制到另一个单元格并修改本地数组。我不知道为什么会这样。有人知道吗?如果需要,我可以提供更多代码。

4

1 回答 1

0

发生这种情况是因为您正在重用单元格,并且在重用单元格后正在运行 configureCellWithText。要解决这个问题,您可以:

  1. 不要重复使用单元格-但这确实会损害您的表现。
  2. 如果您在 6.0 上运行,则可以tableView:didEndDisplayingCell:forRowAtIndexPath:在单元格滚动到屏幕外时取消文本设置操作。
  3. 您可以在将单元格出列时设置的自定义单元格类中创建一个标志。

编辑

因为我不知道你的细胞是如何工作的。除了 sudo 代码概念之外,我很难给你任何东西。

这是我的 sudo 代码:

用于行的 Tableview 单元格... - 出列单元格 - [单元格 cancel_previous_action] - 设置新操作。

于 2013-02-13T17:33:45.210 回答