ios - heightForRowAt 与 estimatedHeightForRowAt 有什么区别?

标签 ios swift uitableview

通常当我想设置行高时再设置

 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 300
    }

estimatedHeightForRowAt 有什么好处我应该什么时候使用它。

更新!如果我想设置 estimatedHeightForRowAt:

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

        return // what should i put here
    }

更新:
如果我按照自己的意愿提供 estimatedHeightForRowAt,是否会影响 tableview 滚动? .例如我给出 estimatedHeightForRowAt 500

最佳答案

iOS documentation 中所述:

If the table contains variable height rows, it might be expensive to calculate all their heights and so lead to a longer load time. Using estimation allows you to defer some of the cost of geometry calculation from load time to scrolling time.

关于ios - heightForRowAt 与 estimatedHeightForRowAt 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45267576/

相关文章:

ios - Swift 中类的函数调用中的 "Expression are not allowed at top level"

swift - 如何在 Swift 中用图像填充表格单元格

ios - 如何在 Swift 中从 AWS Mobile Hub 检索电子邮件和电话号码?

ios - 在自定义 tableviewcell 中更改 UIImage

ios - 如何使用 Cosmicmind/Material TextField 将 TextField 的分隔线也放置在 LeftView 下

ios - 如何将 ScrollView 中的图像上传到网络服务器上?

ios - Objective-C - 来自 Web 服务的 bool 方法

xcode - 快速 UITableView 设置 rowHeight

ios - UITableView.sizeToFit() 只渲染第一个单元格

ios - 使用 twitter swift 4 登录时出错