views:

517

answers:

2

Hi.

What I try to do: If a user is pressing a button, a new view controller is being loaded and pushed to the navigation Controller.

The new view controller is doing some hard database querying in it's ViedDidLoad Method which causes some seconds to get the view loaded.

I'm trying to show a wait indicator before the view is starting to load.

If I try to add a UIActivityIndicatorView as subview of my starting view right before the new view is being allocated, the indicator is shown AFTER the new view finished loading...

I also tried to put the database querying in the ViewDidAppear Method but with the same result.

A: 

The problem is that all UI changes must be performed on applications main thread. If something blocks main thread then UI changes are not applied (UIActivityIndicatorView is not shown in your case).

To solve your problem you must run loading data routines in background thread (e.g. using -performSelectorInBackground:withObject method) leaving main thread for UI.

Vladimir
+1  A: 

Have a look at MBProgressHUD. It's really easy to implement.
The main problem is that all UI changes must be done on the main thread and therefore all tasks that take a relative long time must be done on a background thread.
MBProgressHUD will do this for you. If you want to customize it, just change the code.

bddckr