开发者

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?


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:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜