2

我有点沮丧。我有一个iOS 10项目UITableViewUITableViewAutomaticDimension单元。我正确设置了约束。UITableView cellForRowAt vs willDisplay

起初我映射我的细胞内部

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)

后这我的自动布局单元停止正常工作。

我的理解,在高度cellForRowAt之后,但之前willDisplay计算,所以当我在willDisplay高度映射已被设置为我的手机,我需要重新加载它(这是不好的)。

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

UPDATE:

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

+0

您可以将我的回答标记为答案? –

回答

2

务必设置你的细胞内func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

苹果文件说,大约cellForRowAt

询问ce的数据源将插入到表视图的特定位置。

tableView(_:cellForRowAt:)

另一方面willDisplay可以用于覆盖之前它被吸引到观看细胞的某些性质。如果你不确定willDisplay是否在cellForRowAt中完成所有设置,我会建议。

苹果的医生说大约willDisplay:

此方法使该委托有机会重写基于状态的性质早些时候表视图设置,如选择和背景颜色。

更多willDisplay是这里苹果的文档: tableView:willDisplayCell:forRowAtIndexPath:

编辑:读你所提供的链接后 - 我重申,除非你真的有特殊原因设置你的细胞willDisplayCell ,只需在cellForRowAt

相关问题