gpt4 book ai didi

行删除动画完成后的 UITableView 回调

转载 作者:行者123 更新时间:2023-12-04 15:15:15 28 4
gpt4 key购买 nike

我有一张在顶部和底部单元格下方带有阴影的表格(此处使用 Matt Gallagher 的解决方案:http://cocoawithlove.com/2009/08/adding-shadow-effects-to-uitableview.html)。这些是在 UITableView 类扩展的 layoutSubviews 方法中添加的。

我动态地添加和删除每个主单元格下方的单元格(这些提供了额外的数据)——我们称之为“细节”单元格。一次只有一个打开。当删除最后一个主单元格下方的“细节单元格”时,随着动画开始,阴影向上轻弹到最后一个单元格(细节单元格上方)。这样做是因为 layoutSubview 方法认为表的最后一个单元格在 deleteRowsAtIndexPaths 的动画开始时(而不是动画结束时)发生了变化。

所以,本质上,我需要一种方法来保持细节单元格下方的阴影被删除。不确定执行此操作的最佳方法。如果 UITableView 不再认为该单元格是最后一个单元格,那么我什至不确定如何获取该单元格(因为 UITableView 因此获取该单元格):

NSIndexPath *lastRow = [indexPathsForVisibleRows lastObject];
if ([lastRow section] == [self numberOfSections] - 1 &&
[lastRow row] == [self numberOfRowsInSection:[lastRow section]] - 1)
{
//adds shadow below it here
}

因此,如果 UITableView 仍然认为“详细信息”单元格上方的主单元格是“lastObject”,那么即使捕获动画的开始也没有多大用处。

感谢您的任何想法。

最佳答案

尝试这个

[CATransaction begin];

[tableView beginUpdates];

//...

[CATransaction setCompletionBlock: ^{
// Code to be executed upon completion
}];

[tableView deleteRowsAtIndexPaths: indexPaths
withRowAnimation: UITableViewRowAnimationAutomatic];


[tableView endUpdates];

[CATransaction commit];

关于行删除动画完成后的 UITableView 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6039060/

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