Tutorial :Optimizing the load time of presentModalViewController:


In my NiB, I have several View controllers. When the app launches, all their corresponding ViewDidLoad() calls are called.

in ViewControllerA, I have ViewA that contains a UiScrollView with 100 pictures. In initalize these pictures in ViewdidLoad. So on app launch, all pictures are initalized.

In my Main Menu View Controller, I have a button that when pressed calls presentModalViewController:ViewControllerA

That call is taking 20 seconds.

I thought the pre loading in ViewDidload would optimize this. However, once the call returns and recalled (bringing up this VC the second time, its really quick and instant).

So what is causing this? Why is it taking so long the first time calling presentModalViewController. Internally, is it trying to arrange all the images? Any way of optimizing this? If not, whats the best way to show UiActivityIndicator

Thank you in Advance


This turned out to be too long for a comment.

I would first play around with UITableView to see if it could apply.

If it's completely fullscreen, then you have the UITableView be in portrait, but rotate your pictures in their cells. This will be identical to landscape.

If the scrollview doesn't fill the screen, you can still try UITableView with a view transform to rotate it.

Then your next approach should be to put in placeholders in the scrollview that lazily load the images. If all the images are the same size, then this is very straightforward, and you can optimize memory by only holding a limited number of these cells.

Another crazy idea: make it a UIWebView. That will do all the lazy-load for you.


First, put some NSLog() statements in your -viewDidLoad methods. They probably aren't being called when you think they are. UIViewControllers are lazy. They don't actually load their NIB until someone references their -view.

If by "all their corresponding ViewDidLoad() calls are called," you mean you're actually calling [viewController viewDidLoad] by hand, that won't work and don't do that. That's a delegate method that should only be called by the system.

You could, but shouldn't, get around all this by calling [viewController view]. This will force a load, but this is almost always the wrong answer.

How big are the pictures? Do you really have the memory available to hold all 100 all the time? Could you load these pictures as you need them? What shape are the pictures laid out? Could a UITableView do a lot of the work for you? If their in a grid, you could show 4-5 pictures per UITableViewCell, and then you'd get all of UITableView's optimizations.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »