gpt4 book ai didi

ios - UITableView 的 reloadData 与动态单元格高度不需要的滚动

转载 作者:行者123 更新时间:2023-11-30 13:37:54 25 4
gpt4 key购买 nike

我花了近两天的时间来解决这个问题!而且我还没有找到任何解决方案。

我有一个带有动态单元格高度的表格 View ,因为我正在使用此代码

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 300.0

对于我的 tableView,我使用的是 infinit scroll 库加载更多具有动态高度的数据。

在某些情况下,我会使用更新的数据重新加载我的表格 View !当我调用 reloadData() 时, TableView 向上或向下滚动。修复 estimatedRowheight 应至少为 550.0

tableView.estimatedRowHeight = 550.0

解决此问题后,当我调用 self.tableView.finishInfiniteScroll() 时,我遇到了另一个与 infinitscroll 相关的问题,tableView 向上滚动(跳跃)

self.tableView.beginUpdates()
self.tableView.insertRowsAtIndexPaths(indxesPath, withRowAnimation: UITableViewRowAnimation.Fade)
self.tableView.endUpdates()
self.tableView.finishInfiniteScroll()

我正在使用自动布局!我正在 iOS 9.1

上进行测试

最佳答案

尝试这个,不要在任何地方给表格和单元格赋予高度

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return UITableViewAutomaticDimension
}

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return 44.0
}

关于ios - UITableView 的 reloadData 与动态单元格高度不需要的滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35881118/

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