gpt4 book ai didi

ios - UITableView 重新加载行在 iOS 11.2 中不自然地抽动 TableView

转载 作者:搜寻专家 更新时间:2023-10-31 21:50:04 25 4
gpt4 key购买 nike

通过调用 iOS 11.2 更新新的 XCODE 9.2 后出现奇怪的问题

let indexPath = IndexPath(item: 0, section: 1)
self.tableViewHome.reloadRows(at: [indexPath], with: .none)

这会导致整个 TableView 不必要的抖动,之前这些代码都很好。

iOS 11.2 的 GIF 图片

enter image description here

iOS 11.1 的 GIF 图片

enter image description here

如何停止这种抽搐,我必须在两个单元格之间重新加载表格 View 中的一个单元格。

我们将不胜感激。

谢谢

最佳答案

我的理解是,如果您真的想使用自动调整单元格大小(并且所有单元格的大小都不同),那么上述解决方案不适用于 iOS 11.2,所以我尝试的方法如下:

声明变量来存储单元格的高度

var cellHeightDictionary: NSMutableDictionary // To overcome the issue of iOS11.2

在viewDidLoad中初始化,

override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 125
cellHeightDictionary = NSMutableDictionary()
}

并像下面这样使用:

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cellHeightDictionary.setObject(cell.frame.size.height, forKey: indexPath as NSCopying)
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
if cellHeightDictionary.object(forKey: indexPath) != nil {
let height = cellHeightDictionary.object(forKey: indexPath) as! CGFloat
return height
}
return UITableViewAutomaticDimension
}

这对我有用,希望对你也有帮助

关于ios - UITableView 重新加载行在 iOS 11.2 中不自然地抽动 TableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47690381/

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