gpt4 book ai didi

ios - iOS 中的 HeightForRowAt 和 estimatedHeightForRowAt

转载 作者:搜寻专家 更新时间:2023-11-01 06:58:25 25 4
gpt4 key购买 nike

我在一个 ViewController 中有 2 个 tableview。两个表格 View 的单元格高度不同。

在第一个表格 View 中,我通过 heightForRowAt 委托(delegate)方法进行计算,因为在该表格中,单元格的内容是静态的。第二个是通过 estimatedHeightForRowAt 委托(delegate)方法,因为在该表中,单元格的内容是文本(可能很小或很大)。

所以问题是第二个 tableview 的单元格高度固定为 58。在显示大文本时不会增加。

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if tableView == tblHistory{
let h = ((tableView.frame.size.width - 16) * 7 / 5) + 74
return h
}
else{
return 58
}
}

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
if tableView == tblHistory{
let h = ((tableView.frame.size.width - 16) * 7 / 5) + 74
return h
}
else{
return 58
}
}

注意:我已正确设置所有约束以根据文本调整单元格高度。

最佳答案

the problem is the height of text cell fixed. That is not increasing while large text display.

在 Storyboard的单元格内,您确实必须完美地约束

真的有很多东西要知道。您必须显示(屏幕截图)单元格的 Storyboard ,并显示链接 UILabel 和其他项目的所有垂直约束。

一般来说,您不应“固定”UILabel 的高度,或包含 UILabel 的整体“链”。如果你这样做正确,它的隐式高度将起作用。

关于ios - iOS 中的 HeightForRowAt 和 estimatedHeightForRowAt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52034429/

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