Search code examples
ipadxcode4uigesturerecognizerswipe

Load all view controllers at the launch


I have created an iPad app that has 10 view controllers that swipe left and right to and from each other, and each have 2-10 pages for a vertical UIScrollView. The problem is only the first controller loads at the launch, so each swipe initially takes 10 seconds to load. After the initial swipe I can swipe back and forth with ease, but I would rather have all the load time at the beginning so the user isn't left wondering what's happening.

Is there a way to load everything at once? Should I even be using UIViewController subclass for this?

Thanks!


Solution

  • You can allocate and initialize them all in the application delegate (I think these go in the applicationDidFinishLaunching method, but I'm not at my computer to verify that is the best place). You may want to set their isHidden property to YES (except for the one you want to show first).

    Once they are loaded this way, the applications view controller can be used to change the hidden property when you want a view to show or be hidden.

    If each view really takes 10 seconds to load, you will have an initial load time when the application starts that is 10 seconds times the number of views you are loading. But once they are loaded, you shouldn't have that delay anymore.

    Update: If you want to animate the transitions from one view to another, you will have to use more than the isHidden property (that can't be animated). But you can deal with that later, and still start off by allocating and initializing like I described above.