我有一个包含太多 UITextView 的 UITableViewCell,而且我的性能一直很差。
我想绘制文本,当用户点击文本尝试编辑时,将一个真正的 UITextView 放在那里。
我该如何实现?
最佳答案
在iOS Developer Library你有一个名为 TableViewSuite 的例子,这里有一些关于如何实现 UITableView
的示例,最后一个示例(编号 5)是实现具有性能的 UITableView 的最佳方法,因此我建议您查看此示例。
TableViewSuite
项目说明:
This sample shows how to use UITableView through a progression of increasingly advanced applications that display information about time zones.
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.
Subviews have two costs:
1) Initialization. This can be largely mitigated by reusing table cells. 2) Compositing. This can be largely mitigated by making the views opaque. Often, one translucent subview is fine, but more than one frequently causes frame drops while scrolling.
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.
The fifth example is an extension of the fourth. It displays even more information about each time zone, such as the time and relative day in that time zone. Its shows how you can create a custom table view cell that contains a custom view that draws its content in -drawRect:.
关于ios - 如何提高具有过多 UITextView 的 UITableViewCell 的性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8045380/