sol
sol

Reputation: 6462

UITableView - don't unload cells when they go off screen

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?

Upvotes: 2

Views: 2770

Answers (3)

Jordan
Jordan

Reputation: 21760

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.

Upvotes: 0

Jordan
Jordan

Reputation: 21760

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:

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

Upvotes: 0

Shaggy Frog
Shaggy Frog

Reputation: 27601

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

Upvotes: 5

Related Questions