gpt4 book ai didi

iphone - 为什么调用 insertRowsAtIndexPaths : call heightForRow for all rows?

转载 作者:行者123 更新时间:2023-11-28 19:17:41 24 4
gpt4 key购买 nike

当您有很多单元格时,

heightForRowAtIndexPath 是一项非常昂贵的操作。在我的例子中,我有数千个,所以我想我可以分批分解表格并一次只显示 50 个单元格,并且当用户接近表格 View 边界的末尾时,使用 insertRowsAtIndexPaths:再插入 50 行。但是,每次我插入 50 个新行时,都会为表的所有行调用 heightForRowAtIndexPath,而不仅仅是我刚刚插入的行。这是预期的行为吗?为什么是这样?我的行高必须计算带有字体的字符串的高度,因此每次插入新行时计算整个表格的高度是非常低效的。有任何解决方法吗?

最佳答案

Is this expected behavior? Why is this?

是的,这使得将具有不同高度的行插入到一个表中成为可能。

Are there any workarounds?

如果所有行的高度都相等,则在初始化期间只计算一次高度。
每次调用 heightForRowAtIndexPath 时,只需返回缓存的结果。

关于iphone - 为什么调用 insertRowsAtIndexPaths : call heightForRow for all rows?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11171983/

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