ios - .reloadSections 后的 UITableView 偏移量不正确
问题描述
当我点击显示/隐藏内容时,我有下一个代码。
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 个项目的视频。效果很好 视频1
第一部分有 10 个项目的视频。它有错误。视频 2
解决方案
解决方案是更换
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
和
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat
推荐阅读
- django - 如何在对象过滤器中正确使用日期
- c# - 仅在特定时间无法访问数组
- android - Retrofit 2 处理 JSONArray 或 JSONObject 的动态 api 回调
- nested - 遍历 terraform 中的地图列表列表
- android - 我也想增加选定选项卡和指示器的大小
- python - 将数字列表从 0-5 更改为 0-10 的函数存在零问题
- swift - 从纵向移动到横向时如何修复 UIcollectionView 中的项目宽度?
- python - 使用python进行Nmap扫描并存储在mysql中
- python-3.x - 如何从回归问题的 OOB 分数估计 OOB 错误率
- html - 在 Safari 中显示图标