gpt4 book ai didi

ios - 如果在另一个表更新后调用得太快,tableView.reloadRows 会闪烁

转载 作者:搜寻专家 更新时间:2023-10-31 22:29:51 26 4
gpt4 key购买 nike

This video demonstrates the issue I'm visually having.

每隔一段时间,我将这个 block 称为:

self.tableView.beginUpdates()
self.tableView.insertRows(at: [indexPath], with: rowAnimation)
self.tableView.endUpdates()

self.tableView.scrollToRow(at: indexPath, at: scrollPosition, animated: true)
self.tableView.reloadRows(at: [indexPath], with: .automatic)

让我们不要过多地询问它(insertRows 调用和立即的 reloadRows 调用)。这是解决 SlackTextViewController 中错误的建议解决方案。 The bug in question for those curious.

现在,在别处,我调用:

self.tableView.reloadRows(at: [indexPath], with: .automatic)

当我们在两种情况下处理相同的 indexPath 时,如果这两个 block 运行得太快,您会遇到闪烁。

我会发现通过使用 dispatchQueue( :asyncAfter) 方法。

我该如何处理?

更新:目前,我已经通过使用 dispatchQueue(:asyncAfter) 方法修复了这个问题,避免了竞争条件。不过,我想避免这种情况,所以我会在搜索其他答案时继续这样做。

最佳答案

根据您的评论,如果第二次调用发生在网络调用之后的完成 block 中,我猜您正在使用网络调用的结果。如果是这种情况,如果您需要在单元格中反射(reflect)的更改不影响单元格的高度,您可以在索引路径处获取单元格,检查它是否为零(以防用户将其滚动到屏幕外)如果单元格仍然可见,则直接应用更改。无需重新加载。

关于ios - 如果在另一个表更新后调用得太快,tableView.reloadRows 会闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40776862/

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