iphone - UITableView滚动性能悖论: Make subviews or use -drawRect:?

标签 iphone uitableview

我正在阅读thourg this example (link) ...

从描述来看,这对我来说似乎是悖论:

When implementing a table view cell, there's a tension between optimal scrolling performance and optimal edit/reordering performance. You should typically use subviews in the cell's content view.

When you have an edit or reordering control, using subviews makes the implementation easier, and the animations perform better because UIKit doesn't have to redraw during animations.

结论: subview 速度更快,因为 UIKit 在动画期间不得重绘。所以滚动的时候一定不能一直调用-drawRect:。对吗?

然后,悖论:

If the content is complex, however (more than about three subviews), scrolling performance may suffer. If this becomes a problem, you can instead draw directly in a subview of the table view cell's content view.

结论:更喜欢 -drawRect:直接在表格 View 单元格上绘制。复杂单元格的更好滚动性能。比很多 subview 更好。

那么,好吧。什么是真的? subview 或 -drawRect:哪个更好?

就我而言,每个单元格大约有 12 个 subview 。他们实际上只是想说这个吗? “如果您最多只有 3 个 subview ,请使用它们。但如果您有更多 subview ,请使用 -drawRect: 并直接在单元格上绘制。”。但然后:为什么不总是更喜欢 -drawRect: 那么呢?

最佳答案

您可以将其总结为仅显示与功能。如果您的单元格的任务只是显示不会发生太大变化并保持静态的数据,请绘制它。如果您的单元格的任务是发挥功能,可以更改位置或由用户操纵(或者您有自定义动画),请考虑使用 subview 。

对此并没有真正硬性规定。您的用例可以很好地衡量哪种方法最好。有了 12 个 subview ,我会立即倾向于自定义绘图以获得速度优势。

Why not always prefer -drawRect: then?

通过使用 subview ,您可以免费获得很多东西。动画“更容易”。例如,使用 UIImageView 显示图像可以免费突出显示。这实际上取决于您的细胞的任务。

关于iphone - UITableView滚动性能悖论: Make subviews or use -drawRect:?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2607670/

相关文章:

ios - 选择时如何更改位于 tableVIewCell 上的 UIButton 的图像。在 swift 3

cocoa-touch - 如何以编程方式切换 UITableView 的 NSFetchedResultsController(或其谓词)?

iphone - iPhone 中的语音识别?

ios - 如何删除 UITableView 中的空单元格?

iphone - 在 ios 6 sdk 中获取 facebook 用户详细信息?

iphone - 某些应用程序如何在其应用程序中以编程方式打开设置应用程序

ios - 如何根据按下的按钮选择行?

ios - 我可以从数组中的第二个元素开始填充我的表格 View 吗? ( swift )

iphone - UITableViewCell 变换重复反转

iphone - 有没有 TTPickerTextField 替代方案?也许在iOS4中?