views:

121

answers:

1

Hello. I am new to programming. I have a paging enabled scroll view with many pages (up to ten) and on every page I have a custom button. Every custom button has a custom image. Everything I have made in Interface Builder. When I load the view controller containing this scroll view, it takes a lot of time to load it because it loads all the pages. How can I improve the load time? Can I implement the lazy loading technique in my case? If yes, how exactly, because I am a beginner. Thank you in advance!

+3  A: 

You definitely can. There are several examples of scroll views where the content is loaded/unloaded dynamically as you scroll through.

The following blog post helped me get going with this: http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html

You also want to make sure NOT to use [UIImage imageNamed:] unless you must. This method has internal caching, which is very flakey and unreliable, and if you load enough number of big images, your app will be decapitated fairly quickly -- instead use e.g. [UIImage imageWithContentsOfFile:]. There is a discussion of this on SO here: http://stackoverflow.com/questions/316236/uiimage-imagenamed-vs-uiimage-imagewithdata -- if you're unsure on how to approach things, read that and make up your mind afterwards.

Hope that helps.

Kalle
I have made everything in Interface Builder. That is the difficult point.
Sania
Are you saying that you've put the images in, by hand, in interface builder? You're not adding these to the scroll view after the app has launched? Maybe you could update your answer and include the code where you add these images (unless you DID put them in via interface builder).
Kalle
Yes, I put images on every button with Interface Builder.
Sania
In that case you're kind of out of luck. You will have to start loading these images from within XCode programmatically if you want to be able to do any of the stuff I mentioned above. It may be possible to load each UIView separately using the method I mentioned, but you still have to get down into the code. Try that and see how far you get.
Kalle