tags:

views:

38

answers:

2

I'd like my UIViewController to appear on the screen with a "Loading..." UILabel in the center and then, once that's been displayed, start loading data to display.

How can I achieve this? I tried loading it in viewDidAppear:, but at this point the view has still not been displayed on the screen, so the app appears unresponsive to users. If I try setting a short timer (0.0001 seconds) so that the view will be displayed and then the data loading method gets called in the run loop after that, for some reason the time it takes from opening the view controller to seeing content is about three times as long as it was without the timer. In this case, the Loading... text appears, but the user has to wait way too long.

What's the best way to do this?

A: 

Better do this in a thread from viewDidLoad and call your method in a thread, before calling the thread show your label and when the data is loaded through the thread hide the label.

you can do it like this.

-(void)viewDidLoad{
[self showLabel];
[NSThread detachNewThreadSelector:@selector(loadData:) toTarget:self withObject:nil];
}

Hope this helps. Thanks,

Madhup

Madhup
be sure to put the seperate thread in an autorelease pool or you will get memory leaks
nathanjosiah
+1  A: 

if I have not misunderstand your purpose, I think that you just want sow a 'loading' status to user, right ? if so , I suggest that you may use a simple ViewController to show the label 'Loading...' and then create the MainViw or next view which you want show to user in the end, when it was done, hide the first view show the MainView on screen...

Robin