views:

3529

answers:

3

I have a uitableview that loads fairly large images in each cell and the cell heights vary depending on the size of the image. Scrolling performance is decent, but can sometimes be jerky.

I found these tips I found on the FieryRobot blog:

http://www.fieryrobot.com/blog/2008/10/01/glassy-scrolling-with-uitableview/ http://www.fieryrobot.com/blog/2008/10/08/more-glassy-scrolling-with-uitableview/

Does anyone have any tips for improving uitableview scrolling performance?

+9  A: 
  1. If you are subclassing UITableViewCell, don't use a Nib, write it in code instead. It's much faster than loading Nib files.
  2. If you're using images, make sure you're caching them so you don't have to load from file more than once for each (if you have the memory -- you'd be surprised how much space images take up).
  3. Make as many elements opaque as possible. Similarly, try not and use images with transparency.
Shaggy Frog
Two neg votes? Ooookay...
Shaggy Frog
dont worry... that were trolls. great answer!
Steav
+15  A: 
  1. Cache the height of the rows (the table view can request this frequently)
  2. Create a least-recently-used cache for the images used in the table (and invalidate all the inactive entries when you receive a memory warning)
  3. Draw everything in the UITableViewCell's drawRect: if possible avoid subviews at all costs (or if you require the standard accessibility functionality, the content view's drawRect:)
  4. Make your UITableViewCell's layer opaque (same goes for the content view if you have one)
  5. Use the reusableCellIdentifier functionality as recommended by the UITableView examples/documentation
  6. Avoid gradients/complicated graphical effects that aren't pre-baked into UIImages
rpetrich
+6  A: 

The developer behind Tweetie has written extensively about this and has some code that demonstrates how it was done for that app. Basically, he/she advocates one custom view per table cell, and drawing it manually (rather than subviewing with Interface Builder, among other options).

http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/

Also, Apple has updated its own sample code for TableView in its TableViewSuite tutorials (maybe in response to this?)

http://developer.apple.com/iphone/library/samplecode/TableViewSuite/index.html

beno