There’s a way to preload a modal view controller without showing it?
I’m asking because when I’m displaying the modal view controller (allocating and initializing the view controller class), the view have a little delay to load and display.
After it, when I try to show it again, the delay stops.
I’m using a UITableView, and inside the method scrollViewDidEndDragging I check if the contentOffset.y is less than -90. If so, the user basically “pulled to refresh”, then I’m loading the view.
UINibto preload the XIB into memory.It will pre-decode the object-tree of the XIB into memory, but won’t instantiate the objects in the XIB. Then you can call the
instantiatemethod ofUINibto instanciate the view.viewof aUIViewControllerto be loaded by calling itsviewgetter method (as the view is lazy-loaded, so it will be loaded from the XIB the first time it is accessed).But as you can only instantiate UI objects (from your XIB) on the main thread — as every UI component and UI action has to be done in the main thread — your app will still “freeze” (block the main thread) while you load the view. You can’t for example load the root UIView of your XIB in a separate thread or queue (you will have an runtime exception if you try that).
Use Instruments and its “Time Profiler” tool to check where exactly the loading process of your XIB file takes time. (Maybe it is easy enough to resolve, or maybe you will have some component that you can lazy-load only after the view has been displayed, etc.)