【发布时间】:2021-10-04 04:40:48
【问题描述】:
我想在索引 0 上方的 UITableView 中插入新行,类似于 iMessage 在您向上滚动并加载以前的消息时的操作方式。
这是我当前的实现:
let indexPaths = (0..<newItemsCount).map { IndexPath(row: $0, section: 0) }
tableView.beginUpdates()
tableView.insertRows(at: indexPaths, with: .top)
tableView.endUpdates()
然而,这会导致 tableview 突然跳跃。 这是一个 iMessage 的例子
到目前为止我所尝试的:
- 在我插入新行之前将内容偏移量设置为原始偏移量
- 在我插入新行之前滚动到顶部的单元格,这实际上会导致表格视图闪烁
- 重新加载数据
【问题讨论】:
-
试试这个-tableView.insertRows(at: indexPaths, with: .none)
-
不相关但
begin-/endUpdates()对单个插入操作无用。 -
@vadian 啊谢谢,很高兴知道......
-
@Niv 没有动画无助于表格视图仍然跳跃
-
你能发布你的整个控制器代码吗?一定有你忘记的重新加载数据之类的。
标签: ios swift uitableview