I need an advice what to do when my view controller is loading quite long?
In my situation I have an offline map made with route-me and it takes several seconds to load the map from about 100mb database, then load a lot of markers, put them on the map, etc.
If I run this code in viewDidLoad UI seems unresponsive, because after pressing on tab or button nothing happens for a few seconds while everything is loading. If I put it in viewDidAppear map somehow doesn’t get shown at all until I quit this view controller and go back to it.
If it takes so long you should show a spinner or other “busy” indicator while you load your data on a background thread.
Once your time-intensive process is complete, update the UI back on the main thread and hide your spinner/busy indicator.
Executing code on a background thread is extremely easy – there are several ways to do it – but the easiest/most straight-forward way is probably with
performSelectorInBackground:withObject:as in this example:When you’re ready to run on the main thread again – it’s the same thing, but in reverse using
performSelectorOnMainThread:withObject:waitUntilDone::Good luck.