iphone - heightForRowAtIndexPath 被调用所有行 & 在性能问题之前 UITableView 中有多少行?

标签 iphone ios uitableview heightforrowatindexpath

我想我已经读过关于 UITableView 的内容,heightForRowAtIndexPath 不会在所有行上被调用,而只会在可见的行上被调用。然而,这不是我所看到的。例如,我看到数百次调用 heightForRowAtIndexPath 来处理 iPhone 方向改变的简单情况。

因此,我在这里假设对于实现了 heightForRowAtIndexPathUITableView,它确实(即 heightForRowAtIndexPath)为所有行调用(不仅仅是可见的)...如果这不太正确,请告诉我。

问题:鉴于上述情况,通常在出现性能问题之前,UITableView(其中实现了 heightForRowAtIndexPath)可以有多少行?

是否有解决性能问题的方法?即为每一行设置标称/标准高度并且不实现 heightForRowAtIndexPath,但随后仅在显示时正确设置每一行高度并在此处正确设置......但是哪种方法可以在?

最佳答案

查看 tableView:heightForRowAtIndexPath: documentation 中的讨论部分

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

因此您应该使用 UITableView 的 rowHeight 属性。如果您需要不同的高度,那您就不走运了,因为您必须使用 tableView:heightForRowAtIndexPath:

据我所知,无法更改显示时的行高。
tableview 必须事先知道正确的大小,否则会一直出现难看的位置偏移。

关于iphone - heightForRowAtIndexPath 被调用所有行 & 在性能问题之前 UITableView 中有多少行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5324205/

相关文章:

objective-c - 通过 AVAssetReader 读取样本

iphone - SQLite 中没有数据

ios - UISwitch 出现在其他单元格上!毛刺?

ios - 在传递数据之前在 tableview 中丢失行 id

iphone - 注销 iphone 时重置所有选项卡

iphone - 如何在 iPhone 编程中将临时文件的位置更改为高清文件

iphone - Cocoa-Touch:内存管理

ios - 在 drawrect 方法中绘制带动画的矩形?

ios - 使用分段控件切换*和刷新* subview

ios - 每秒运行一个 NSTimer 会有多费力?