views:

532

answers:

3

Hi there,

I'm using several images to style UITableViewCells and I want to make sure I'm doing things correctly, firstly to ensure good memory management, and secondly to make sure things are as fast as possible (I'm having troubles with the sluggyness of the scrolling!).

I know that using [UIImage imageNamed:] will cache the images for speed, so is it okay to use that for getting all my images? Or is it better to only call that once per UITableViewController and store the image as an instance variable, reusing the same UIImage object for all my cells?

I'm using transparent PNGs and clear coloured views in my table and cells to get the look I'm going for. Are there any tips on ensuring it renders as quick as possible to make sure the table view scrolling is smooth? At the moment I only have about 10 rows (cells) and it's already quite sluggish. I'm using a fetched results controller to get my data so I don't think it could be that causing it.

Many thanks,

Michael

A: 

I guess it's better that you reuse the UIImage instance for all your cells, this way you can retain it and make sure it isn't released in case of a memory warning, a guarantee that you don't have for [UIImage imageNamed:]'s cache. Also, a tip for keeping it smooth is to make sure you don't have overlapping views, especially transparent ones.

luvieere
+1  A: 

The tip to using transparency is don't. If you have multiple overlapping elements see if there is some way to pre-render the transparent effect - that more than almost anything, is what will kill table scrolling performance.

The other big hit is if you do not properly reuse cells.

The fetched results controller should do nothing to slow things down. You could try using Instruments to make sure of that...

Kendall Helmstetter Gelner
So is it a problem simply having an opaque cell with a gradient on it and 2 transparent UILabels (Similar to the UITableViewCellStyleSubtitle)? For me that setup is still being quite slow to scroll and drag. It's a shame if that's true!
Michael Waterfall
Yes that is exactly the problem. As it scrolls, it is redrawing all that... consider putting that all in a view, rendering the results into a UIImage and using that in drawRect. Or in drawRect drawing the string text directly on the gradient.
Kendall Helmstetter Gelner
A: 
  1. If you are using the same image on all of your table cells then it is good to get the image from system image cache by +(UIImage)imageNamed:(NSString*)inName API.

  2. Try to get each of your cell by making use of dequeueReusableCell API of UITableViewCell. If this returns nil then only create a new cell object.

  3. If your table view color is transparent(UIClearColor) then set the opaque property of the table view to NO.

Shreekara