gpt4 book ai didi

iphone - heightForRowAtIndexPath : was executed before cell is show?

转载 作者:行者123 更新时间:2023-11-28 20:30:37 25 4
gpt4 key购买 nike

比如tableView有100行,heightForRowAtIndexPath:在第100行显示之前就已经执行了。

为什么?为了计算tableView的contentSize

谢谢!

最佳答案

来自 Apple's documentation :

Every time a table view is displayed, it calls tableView:heightForRowAtIndexPath: on the delegate for each of its rows

是的,它在显示单元格之前被调用。如果您考虑一下,如果表格以相反的方式进行,它将创建一个具有标准高度的单元格,将内容放入其中,获取实际高度,然后调整单元格大小/移动单元格。那可不太好。

这可能会导致性能问题,因此您应该只在具有不同高度的单元格时使用它:

The method allows the delegate to specify rows with varying heights. If this method is implemented, the value it returns overrides the value specified for the rowHeight property of UITableView for the given row.

There are performance implications to using tableView:heightForRowAtIndexPath: instead of the rowHeight property. Every time a table view is displayed, it calls tableView:heightForRowAtIndexPath: on the delegate for each of its rows, which can result in a significant performance problem with table views having a large number of rows (approximately 1000 or more).

否则,如果所有单元格的高度都相同,请使用 rowHeight 属性,并且不要实现 tableView:heightForRowAtIndexPath:

关于iphone - heightForRowAtIndexPath : was executed before cell is show?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12262588/

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