iPhone UITableViewCell performance adding multiple Views vs one View with drawRect
I am creating some UITableViewCells
with several custom items inside, my question is what route to go:
1) Add all I need as separate views to contentView, using UILabels
for text and UIImageViews
for images (currently using this)
or
2) Add a single subclassed View to contentView, and all my text as NSString
then my Images and UIImages
and draw everything at 开发者_开发技巧drawRect
What would perform better, and in what scenarios would one be the better choice over the other?, as I see it unless you are actually drawing lines or something in the contentView, simply going with option 1 would be easier, and according to this Cocoa with love custom cells it is more efficient although it is a bit old, so I don't know if this has changed.
So what is better for performance and in which situation would you definitely use one over the other?
Start with the first method of using separate UILabel's and UIImageView's. Test on actual devices and optimize if you see performance problems.
Depending on the content I've had option 1 be faster than drawing everything in one view. Especially when that view had to draw images. UIImageView's are heavily optimized by apple.
A good way to get metrics on performance is the Core Animation instrument.
I think drawing the text yourself would be marginally more efficient. However, as long as you keep the backgrounds of all your labels opaque, I doubt the difference would be enough to matter, so go with whatever is easiest to program, and avoid premature optimisation.
(The opaque backgrounds thing is quite important — labels with transparent backgrounds are a big cause of inefficiency in table views. Even so, unless you have hundreds it probably won't be much of a problem.)
精彩评论