开发者

iphone put loading screen until tableview is ready to go

开发者 https://www.devze.com 2023-03-26 14:17 出处:网络
In my app, I use several tableviews I need to put loading screen when user click on one of cell in tableView.I attempted to p开发者_如何学编程ut new UIView (activityIndicator and label) and then call

In my app, I use several tableviews I need to put loading screen when user click on one of cell in tableView. I attempted to p开发者_如何学编程ut new UIView (activityIndicator and label) and then call

[[self navigationController] pushViewController:newController animated:YES];

then I can display loading screen while new tableView is preparing data. But this approach didn't quite work, in fact, loading screen didn't even show up and just stuck at previous tableview until new tableview is ready.

So I attempted the other way, that put loading screen with NSOperation/NSOperationQueue. It works but loading screen comes up a little bit late (showed in middle of working of new tableView).

I want to show loading screen right after user click on cell, how could I resolve this problem?


I would suggest that your data loading code is placed on a background thread and started. Then put up a "loading..." view or something. This keeps the display responsive. When the data loading is finished it can notify the main thread that the data is ready and the main thread can then take down the "Loading ..." display.

In other words, read up on using threads when long running tasks such as data loading are required.


Use [NSThread detachNewThreadSelector:(SEL)aSelector toTarget:(id)aTarget withObject:(id)anArgument] instead of NSOperation. Put your tableView process code in a separate method and call it in the detachNewThreadSelector:@selecot(yourMethodName). Before creating this thread start animating your activity controller and stop when the the thread is finished. You can find complete reference of NSThreading here -> http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/Reference/Reference.html . Hope this helps.

Happy Coding!

0

精彩评论

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