views:

62

answers:

3

My tableView consists of 5-10 cells, each of which contains a scrollview of images. The problem is that when a cell goes off screen, it removes all the images and then reloads them when the cell comes back on screen. I know this is done for performance reasons, but in this case it just looks bad. Is there a way to prevent the unloading of cells when they go off screen?

+1  A: 

Yes, of course. The general strategy is to preload all your UITableViewCell objects yourself. You can do this in viewDidLoad and unload them in viewDidUnload, storing them in an NSMutableArray, and then referencing the appropriate index in the array in your implementation of tableView:cellForRowAtIndexPath:.

Shaggy Frog
ok, will look into this.
sol
@sol Be careful about memory usage; if pre-loading all your cells results in requiring an inordinate amount of memory, your app might start having problems. Be sure to measure memory usage of your app with Instruments before and after the changes to be sure your memory footprint stays reasonable.
Shaggy Frog
A: 

You should have a pretty good reason for not doing things the Apple way. With 5-10 cells, it doesn't sound like you have a good reason. Maybe you can improve the loading of cells using background threads in NSOperationQueue.

This post may be helpful:

http://stackoverflow.com/questions/1408997/dynamic-uiimage-content-loading-in-uitableview-code

Jordan
Well, imagine a row of height 200px with 10 images across the screen on an iPad. It looks ridiculous when that row barely goes off the bottom of the screen, all the images disappear and then reappear when the row is moved back up on screen (they get reloaded from a server).
sol
`NSOperationQueue` (singular) is not the right tool for the job, here
Shaggy Frog
Caching images sounds sensible here.
tc.
A: 

Thanks for for the additional explanation. It was quite helpful. By calculating the height if the uitableview based on the height of the uitaleviewcells, you may be able to avoid the problem you're having, without disabling reusable cells. Additionally, if you are reloading cells from the network, you'll definitely benefit from some caching, as mentioned earlier.

Jordan