当我点击显示/隐藏内容时,我有下一个代码。
func showHideAssets() {
isOpenHiddenAssets = !isOpenHiddenAssets
tableView.beginUpdates()
tableView.reloadSections(IndexSet(integer: 1), with: .fade)
tableView.endUpdates()
}
当第一个部分包含很多项目时,在重新加载部分表格后滚动到底部且偏移量不正确
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return 10
}
return isOpenHiddenAssets ? assetsHiddenItems.count : 0
}
视频的第一部分有 3 个项目。它运作良好 video 1
视频的第一部分有 10 个项目。它有错误。 video 2
最佳答案
解决办法是更换
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
与
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat
关于ios - .reloadSections 后 UITableView 的偏移量不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50098984/