views:

880

answers:

3

Hello everyone -

One of the tabs of my UITabBarController takes some time to work before it can be displayed.

What is the best way to display a "Now Loading" before the viewcontroler completes its work?

I tried setting up a "now loading" view in the tab's viewController's viewDidLoad method, then I do the work in viewDidAppear, setting a flag to not do the work again on next time through viewDidAppear.

However, I never see the "now loading" view... some optimizing must be getting done -- the viewcontroller's viewDidAppear is called before the TabBarControllerDelegate didSelectViewController.

Is there a UITabBarController mechanism that would allow for a placeholder view to be displayed before the viewcontroller is displayed?

Any ideas?

Thank you- Matt

+2  A: 

I could be wrong, but perhaps your problem is that by doing the time-consuming work in viewDidAppear, you're blocking the main event thread so that the view doesn't update until the work is complete. I.e. you set up the "now loading" in viewWillAppear, but you never see it since, by the time viewDidAppear completes, it's done with the heavy work.

Daniel Dickison
+1  A: 

The technique to use here is this:

  1. put up a "Loading view" in your controller's viewWillAppear: or viewDidLoad: method
  2. then, spawn a new thread to do the actual loading (or whatever time consuming process you're doing)
  3. when complete, send a message to the controller (using the delegate pattern, for example) that the "loading" is done
  4. finally, remove the Loading view and let the user proceed

Doing it this way leaves your application interface still usable, even though the particular view controller is busy.

There are no build in methods to do this, you'll have to code it all yourself.

August
+1  A: 

NSObject's performSelector:withObject:afterDelay: method can be useful here. Display your "Please wait" alert or view, or whatever, then use performSelector:withObject:afterDelay: to start the actual work. Your loading will be delayed until after the next execution of the event loop, by which time the user interface will have been redrawn.

Mark Bessey