cri*_*ka3 3 uitableview ios swift
通常当我想设置我的行高然后设置
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 300
}
Run Code Online (Sandbox Code Playgroud)
我estimatedHeightForRowAt
应该什么时候使用它有什么好处。
更新!如果我想设置estimatedHeightForRowAt:
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return // what should i put here
}
Run Code Online (Sandbox Code Playgroud)
更新:
如果我按照我的意愿提供estimatedHeightForRowAt,是否有任何效果表视图滚动?. 例如我给出了estimatedHeightForRowAt 500
当您有一些自定义单元格的高度与大多数其他单元格不同时,这种差异变得更有意义。在这种情况下,操作系统使用estimatedHeightForRowAt
默认值(这可以优化您的加载时间),但是如果为行指定了不同的高度,那么它将使用它。
至于放什么东西:
\n\n如果没有变化,那么您将输入相同的 300。基本上,您将默认/最期望的高度放在那里。对于 heightForRowAt 根据您的需要,您可能需要根据部分/行进行切换并更改高度。如果没有任何变化,那么仍然只需将 300 放在那里
\n\n我不确定这是否是你问的原因,但如果你问这个是因为你有不同高度的动态 tableViewCells,那么解决方案是:
\n\nrowHeight
为UITableViewAutomaticDimension
.estimatedRowHeight
或实现高度估计委托方法。基本上做:
\n\noverride func viewDidLoad() { \n super.viewDidLoad()\n\n self.tableView.estimatedRowHeight = 80 // or any other number that makes sense for your cells\n self.tableView.rowHeight = UITableViewAutomaticDimension\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n\n\n如果你不给出,estimatedRowHeight
那么 tableview 将使更多的单元格出队,因为它试图变得聪明,并且需要为平滑滚动做好准备。它将触发您的cellForRow
&willDisplay
回调
如果你给出estimatedRowHeight
一个值,那么它不会再将单元格出队到屏幕外
归档时间: |
|
查看次数: |
5040 次 |
最近记录: |