UITableView cellForRowAt 与 willDisplay

Ale*_*xZd 5 uitableview ios autolayout uitableviewautomaticdimension

我有点沮丧。我有一个iOS的10项目UITableViewUITableViewAutomaticDimension单元格。我正确设置了约束。

最初我在里面映射我的细胞

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

一切正常,但后来我读了一篇文章:https : //medium.com/ios-os-x-development/perfect-smooth-scrolling-in-uitableviews-fd609d5275a5#.4rnbc4vyg并将我的数据映射移动到

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)

在此之后,我的自动布局单元格停止正常工作。

我的理解是 at height 是在 after cellForRowAtbut before计算的willDisplay,所以当我willDisplay已经为我的单元设置了高度映射时,我需要重新加载它(这不好)。

任何人都可以证明/解释这一点?

更新:

发帖提问后,发现这篇文章:https : //tech.zalando.com/blog/proper-use-of-cellforrowatindexpath-and-willdisplaycell/

Sal*_*ior 6

总是在里面设置你的手机 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

苹果文档说关于cellForRowAt

要求单元格的数据源插入到表格视图的特定位置。

tableView(_:cellForRowAt:)

将显示可用于在绘制单元格以供查看之前覆盖单元格的某些属性。如果您不确定 willDisplay,我建议您在 cellForRowAt 中进行所有设置。

苹果的文档说 willDisplay:

此方法使委托有机会覆盖先前由表视图设置的基于状态的属性,例如选择和背景颜色。

更多关于 willDisplay 的信息在 Apple 的文档中: tableView:willDisplayCell:forRowAtIndexPath:

编辑:阅读您提供的链接后-我重申,除非您确实有特定理由在willDisplayCell 中设置单元格,否则只需在cellForRowAt 中进行设置