为所有行调用heightForRowAtIndexPath&在性能问题之前,UITableView中有多少行? [英] heightForRowAtIndexPath being called for all rows & how many rows in a UITableView before performance issues?

查看:126
本文介绍了为所有行调用heightForRowAtIndexPath&在性能问题之前,UITableView中有多少行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为我已经读过 UITableView ,所有行都没有调用 heightForRowAtIndexPath ,但是只有那些可见的。然而,这不是我所看到的。我看到了对 heightForRowAtIndexPath 的数百次调用,例如iPhone的方向改变的简单情况。

I thought I had read that for a UITableView that heightForRowAtIndexPath doesn't get called on all rows, but only on the ones that will be visible. This isn't what I'm seeing however. I'm seeing hundreds of calls to heightForRowAtIndexPath for the simple situation of the orientation being changed of the iPhone for example.

所以我假设这里为 UITableView heightForRowAtIndexPath 已实现,它会(即 heightForRowAtIndexPath )调用所有行(而不仅仅是可见行)...让我知道这是不是很正确。

So I'm assuming here therefore that for a UITableView with heightForRowAtIndexPath implemented, it does (i.e. heightForRowAtIndexPath) get called for all rows (not just the visible ones)...let me know if this isn't quite correct.

问题:鉴于上述情况, UITableView 中有多少行(其中 heightForRowAtIndexPath 已经实现)你可以在性能问题发生之前发生吗?

QUESTION: Given the above, how many rows in a UITableView (where heightForRowAtIndexPath is implemented) can you have before performance issues occur typically?

是否有解决性能问题的方法?即为每一行设置标称/标准高度而不实现 heightForRowAtIndexPath ,但是只有在显示时才正确设置每一行高度并在此处正确设置...但是方法会这样做吗?

Is there a way around the performance issues? i.e. set a nominal/standard height for each row and not implement heightForRowAtIndexPath, but then correctly set each row height only when it is displayed and set it correctly here...but which method would one do this in?

推荐答案

查看 tableView:heightForRowAtIndexPath:文档


该方法允许委托指定高度不同的行。如果实现了此方法,则它返回的值将覆盖为给定行的UITableView的rowHeight属性指定的值。

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.

使用tableView会对性能产生影响:heightForRowAtIndexPath:而不是rowHeight属性。每次显示表视图时,它会在每个行的委托上调用tableView:heightForRowAtIndexPath:这会导致表视图具有大量行(大约1000或更多)的显着性能问题。

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).

所以你应该使用UITableView的 rowHeight 属性。如果你需要不同的高度,那你就不幸了,因为你必须使用 tableView:heightForRowAtIndexPath:

So you should use the rowHeight property of the UITableView. If you need different heights you are out of luck because you have to use tableView:heightForRowAtIndexPath:.

AFAIK无法在显示时更改行高。

tableview必须知道之前的正确尺寸,否则会有丑陋职位一直在变化。

AFAIK there is no way to change the row height at display.
The tableview has to know the correct size before, otherewise there would be ugly position shifts all the time.

这篇关于为所有行调用heightForRowAtIndexPath&在性能问题之前,UITableView中有多少行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆