开发者

How can I populate a UIViewController after it's loaded?

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 开发者_如何学Csetting 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?


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...


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];
}

Update

- (void) loadData:(id)object{  
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
   //Network Operations
   //...  
   //...  
   //...  
   //...  
   [self performSelectorOnMainThread:@selector(reloadView:) withObject:arg waitUntilDone:[NSThread isMainThread]];  
   [pool release];  
}  

Hope this helps. Thanks,

Madhup

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜