How can I use drawRect to load an image in a UITableView
I have a grouped UITableView with some large images. However, scrolling performance is quite poor (note: it was excellent before the iOS 4 upgrade, now it's very jittery). I've read that using drawRect instead of adding subviews to the cell could improve performance.
First question: Is that true?
Second ques开发者_JAVA百科tion: If it will increase performance, how can I implement it? I've been looking at the UITableViewSuite sample code example #5 which does this, but I'm having a lot of trouble adapting their code to work with my project. Are there some other good examples of how to do this?
Thanks for the help!
Yes it is very true.
Basically what you want to do is implement a custom UIView for the content view of you UIImageViewCells. Inside that custom view, you implement drawrect to draw out your cell.
There is a fantastic session video from WWDC 2009 that demonstrates this. I believe that video is now available to anyone in the iPhone Developer Program. I'll edit this answer if IO can find the link. The biggest performance gain is due to the fact that with custom drawing the Tabel View does not have to composite many layers together.
If the only reason you are having slow scrolling is due to your use of large images, this may not help you much. I would make sure that your images are not being scaled up or down, and that you load them in lazily. Don't load images while the table view is being scrolled rapidly - this will kill performance.
精彩评论