Michael Waterfall
Michael Waterfall

Reputation: 20569

UIImage Performance and Optimisation with UITableViews

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

Upvotes: 0

Views: 1222

Answers (3)

Shreekara
Shreekara

Reputation: 149

  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.

Upvotes: 0

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...

Upvotes: 1

luvieere
luvieere

Reputation: 37494

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.

Upvotes: 0

Related Questions