小编pau*_*uln的帖子

dequeueReusableCellWithIdentifier在IOS 7中返回处于编辑状态的单元格

在7之前的IOS版本中不会发生以下问题.

使用UITableView的幻灯片编辑界面删除项目,删除项目并滚动后,新显示的单元格(从中返回dequeueReusableCellWithIdentifier)如下所示:

https://dl.dropboxusercontent.com/u/87749409/Screenshot%202013.09.27%2016.08.30.png

[该图像可能永远不可用,所以这里有一个描述:滚动后,新单元格仍处于最终编辑状态,DELETE按钮仍然可见,单元格内容在屏幕左侧.]

此外,返回的单元格甚至editing设置了其标志.

我用来删除单元格的代码如下所示:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        // Find the item that this cell represents
        NSDictionary *item = [self itemForRowAtIndexPath:indexPath];
        if (!item) return;

        [tableView beginUpdates];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
        [tableView endUpdates];

        // Remove it from the data store
        [Inventory removeInventoryItem:item];
    }
}
Run Code Online (Sandbox Code Playgroud)

我能够通过黑客解决方案克服这个问题.代码(带有hack)是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    InventoryCell *cell = [tableView dequeueReusableCellWithIdentifier:kInventoryCellID];

    // HACK - here we create a new cell when …
Run Code Online (Sandbox Code Playgroud)

uitableview

14
推荐指数
1
解决办法
3669
查看次数

标签 统计

uitableview ×1