Tricks for improving iPhone UITableView scrolling performance?
- If you are subclassing
UITableViewCell
, don't use a Nib, write it in code instead. It's much faster than loading Nib files. - 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).
- Make as many elements opaque as possible. Similarly, try not and use images with transparency.
#1 performance killer for UITableView scrolling is drawing shadows on any cell view layer, so if scrolling performance matters then don't do shadows unless basically it doesn't slow down your main thread.
thought this had to be said since none of the accepted answers made mention of shadows and layers. :+)
- Cache the height of the rows (the table view can request this frequently)
- 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)
- Draw everything in the
UITableViewCell
'sdrawRect:
if possible avoid subviews at all costs (or if you require the standard accessibility functionality, the content view'sdrawRect:
) - Make your
UITableViewCell
's layer opaque (same goes for the content view if you have one) - Use the reusableCellIdentifier functionality as recommended by the
UITableView
examples/documentation - Avoid gradients/complicated graphical effects that aren't pre-baked into
UIImage
s
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).
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?)
TableViewSuite