Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I lazy load 100+ pages in a UIScrollView with paging enabled?

I'm creating a comicbook-like application. I'm using a UIScrollView with paging enabled to display the hi-res full-screen images (the app works similar to Photos.app but with zooming disabled). The final product will have nearly 200 images that need to be paged through by the user. How do I go about setting up the UIScrollView for such a large number of pages?

This would be fairly easy to accomplish with just straight UIViews, but the "feel" of the UIScrollView is just so much nicer with the bounce, etc that I think it adds more value to my app. How should I approach making it work?

like image 830
user2393462435 Avatar asked Jun 28 '10 13:06

user2393462435


1 Answers

Checkout Apple's sample code for PageControl. It shows you how to use a UIScrollView and UIPageControl to cycle through view controllers (just like the photo app). Each page is loaded only as needed.

Basically to achieve lazy loading you start off with an array of empty view controllers. Then as you scroll you load only the current page's view controller as well as the previous and next ones so that scrolling appears smooth. Just look over the sample project, it's fairly short and simple to follow. It should at least get you started. The UIScrollView will tell the appropriate controller when to load itself. It is then the controller's responsibility to load its content (in your case an image).

Good luck.

like image 161
nebs Avatar answered Sep 20 '22 11:09

nebs