Search code examples
iphoneobjective-cmultithreadingpushviewcontroller

(iphone) pushViewController in background thread?


IPhone SDK - Leaking Memory with performSelectorInBackground

seems to suggest you can actually pushViewController in background thread.

But I get a warning from stackoverflow people that I shouldn't do this.
eg. (iphone) start timer from background thread?

is pushViewController considered "UI updating"?
(because I know that UI updating should be done in main thread only)

If it is so,
when a viewController takes a while to load, and want to show an indicator while loading.
What is my option?


Solution

  • Couple of strategies here.

    1) BEFORE you do the push, but at the point you know you are going to do it, bring up a suitable activity view on the current view. I do this in some apps where you click on a row in a table but the pushed view has to do some web comms that takes time, so I leave the table cell highlighted in blue and add a white spinner to the left of the disclosure indicator. Works well.

    2) Use lazy loading to get the new view controller on screen quickly, but defer the heavy code until after it has loaded so that the new controller can look after it's own activity view. By lazy loading I mean you should do as little as possible in the init method and make careful use of viewdidload / viewwillappear / viewdidappear etc to spread the work out and get an activity view on screen as soon as you can.