gpt4 book ai didi

swift heightForRowAt indexPath 不更新

转载 作者:行者123 更新时间:2023-11-30 12:05:54 24 4
gpt4 key购买 nike

使用此代码,我根据数组中的项目数设置单元格的自动尺寸。它可以工作,但是当我使用另一个 viewController 添加一些新项目然后返回到此时,即使数组数量增加,高度也不会更新。

我在viewDidAppear中获取数组

有人可以帮助我吗?

  override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {


print("called")

let misure = self.array.count

let cellHeight = CGFloat(50.0 * Float(misure))

print(cellHeight)
print(misure, " misure")

let section = indexPath.section
let row = indexPath.row
if section == 3 && row == 0{
return 100.0
}else if section == 4 && row == 0{
return cellHeight + 60.0
}
return 44.0


}

在viewDidLoad中我已经设置了

tableView.estimatedRowHeight = 44

最佳答案

我认为如果你调用tableView.layoutIfNeeded()应该会更好。这将更新任何处于挂起状态的布局更新。没有尝试用这个修改高度,但它应该可以工作。

关于swift heightForRowAt indexPath 不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46689028/

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