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