I've got a bunch of "slides" which I'm trying to show on the iPad, one at a time, using a UIScrollView. The "slides" are various subcl开发者_运维问答asses of the UIViewController
class.
I'm storing my slides in NSUserDefaults
, represented by NSDictionaries. At startup, I, load the NSArray of NSDictionaries and loop through them, passing the views to the UIScrollView.
Right now this is inefficient, because all of the slides are being held in memory even when they offscreen. I suspect that I should make it behave a little more like the UITableViewController, in terms of reusing slides and releasing slides when they are offscreen and recreating them as they come onscreen.
I have two questions.
Firstly, how does UITableViewController handle the cell-swapping? Where can I find some sample code or algorithms?
Second, How can I re-use slides if they are not all of the same type?
I wrote an answer about a cyclic UIScrollview here:
How to implement a cyclic UIScrollView?
If you use that approach then you only really need 3 views loaded at any time.
If your views are not all the same type then you just need to implement as much of the commonality as you can into a UIView subclass and perform necessary customisation (setting the image etc.) before display. It should be possible to create only three of them. The one you are scrolling towards begins to be displayed, the one you are scrolling away from is modified for display as it scrolls into view...
A B C
Three views - A and C are not visible, B is visible.
If you scroll to the right some of B, some of C is visible. A can be reused and logically moved to follow C so you have
B C A
Keep scrolling to the right, alter B and make it logically after A
C A B
If you scroll in the other way same idea but do it in reverse.
精彩评论