开发者

Managing a large number of expensive UIViews in an UIScrollview

The iPad app I am designing is going to show a full screen UIScrollView allowing the user to flick through a large number开发者_高级运维 (200 or more) of images - all the same size, no paging. The images are to be loaded from the web and don't have a predefined ordering. Right now what I do is

  1. I load and parse an XML feed which contains references to the images I load, plus metadata which I am showing on the flip side. I store all this in separate objects that manage a front and back view and flipping between those.
  2. The created objects' views are placed on the UIScrollView in a grid, showing a placeholder image at first.
  3. As soon as the image URL is set in the object, it fetches the image itself using an `NSURLConnection`. When the image is fully loaded, it replaces the placeholder image.

This works well enough for a limited number of objects (even though the UI is unresponsive at times), but it does not scale up. The app crashes when I load more than 60-70 custom view controllers. Most of these are offscreen of course - the images are 280x280 each so only 12 will be visible at any given time.

I guess I need to find a way to still keep loading the data in the background but to manage keeping only those views that are actually on (or near) the visible extent of the UIScrollView. Do I need to use Core Data to manage this? If you handled a similar challenge I would love to hear how you solved this - I am guessing it is quite a common one.


You don't load 60-70 view controllers. You only have the number of view controllers on the screen, and when the view scrolls (say) down, you take the controller at the top, change the graphic for one you have stored and put it at the bottom.

The others you are loading you can download in the background. You don't need core data (although you can use it if you want to).

Have a look at the apple videos on scroll views, they cover this.


This is how I did this. I only showed 3 UIView's at the time and every time the user goes forward I unload the first UIView and load a new UIView. The user doesn't notice this, because the next screen and previous screen are always loaded (3 UIViews)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜