美文网首页
解决tableView展开折叠刷新section时滚动到顶部

解决tableView展开折叠刷新section时滚动到顶部

作者: 奋斗的遗忘人 | 来源:发表于2022-09-22 15:28 被阅读0次

//从 iOS 11 开始 UITableView 默认启用 Self-Sizing 的锅,需要关闭这个 Self-Sizing 才行,关闭的办法是:

self.tableView.estimatedRowHeight = 0
self.tableView.estimatedSectionHeaderHeight = 0
self.tableView.estimatedSectionFooterHeight = 0

需要关闭动画的话可使用如下方法

UIView.performWithoutAnimation {
      self.tableView.reloadSections(IndexSet.init(integer: section), with: .none)
 }
或者
 UIView.animate(withDuration: 0) {[unowned self] in
       self.tableView.reloadSections(IndexSet.init(integer: section), with: .none)
 }

相关文章

网友评论

      本文标题:解决tableView展开折叠刷新section时滚动到顶部

      本文链接:https://www.haomeiwen.com/subject/ewsnortx.html