gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:13:45 24 4
gpt4 key购买 nike

iOS 7之前的版本不会出现以下问题。

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

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

[该图像可能不会永远可用,因此这里有一个说明:滚动后,新单元格仍处于最终编辑状态,“删除”按钮仍然可见,并且单元格内容在屏幕左侧。]

此外,返回的单元格甚至还有 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];
}
}

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

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

// HACK - here we create a new cell when we try to reuse deleted cells.
// Deleted cells, when re-used, would still appear as if they were edited,
// with the cell slid off to the far left and the DELETE button visible.
while(cell && cell.editing)
{
cell = [tableView dequeueReusableCellWithIdentifier:kInventoryCellID];
}

if (!cell)
{
cell = [[InventoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kInventoryCellID];
}

return cell;
}

通过 hack(while 循环),会生成一个不处于编辑状态的新单元格。这会导致一些内存浪费,但确实会产生正确的结果。

我想知道 prepareForReuse 中是否有我需要做的事情重置编辑状态的方法。目前,我的prepareForReuse方法仅使用默认值初始化内部控件(标签等)。

我尝试调用setEditing:animated:在删除单元格时的 UITableViewCell 和 UITableView 上,prepareForReuse每当 dequeueReusableCellWithIdentifier:返回的单元格仍然具有 editing标志已设置,但似乎没有解决问题。

最佳答案

我遇到了这个问题,对我来说答案是“doh”时刻。确保在您自己的实现中调用 prepareForReusesuper 实现。

关于uitableview - dequeueReusableCellWithIdentifier 返回 IOS 7 中处于编辑状态的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19060600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com