开发者

UIActivityIndicatorView with UITableView in Navigation Controller

I am working on a an application which is very simple a navigation controller with a table view when the user clicks a row, he is directed to the details view.

However, the details view pulls data from Core Data. i am pulling a relatively large amount of data that takes about three seconds to load.

I wanted to add that UIActivityIndic开发者_开发技巧atorView to show progress.

I tried to start the animation once the user clicks the row, so i set it to animate in didSelectRowAtIndexPath

For some reason, the Activity Indicator doesn't start before the pushing of the details view.

Any idea why? or the best way to implement such an idea?

~Adham


Because you start the animation and then start a large operation in the same thread. Consider running that 3 second operation in a new thread. Look at NSOperationQueue and then create a NSOperation to run that procedure. It will work this way.


The UI doesn't update until the end of your run loop. You are, in sequence, displaying the activity monitor, then pushing the new table view, and then the UI updates. You need to change this order.

You can either move something to a different thread, or you could perhaps delay the loading of the new table view by calling performSelector:afterDelay: with a delay of 0. That will delay the loading of the new table view until after the activity indicator appears in the UI. Now, it's still all on the same thread, so you will be blocked from doing anything, but if the animation is threaded in the activity monitor, it would make for a quick and easy solution.


Call method in thread:

[NSThread detachNewThreadSelector: @selector(loadMethod) toTarget:self withObject:nil];

See following for more details:
http://iphone.zcentric.com/?s=UIActivityIndicatorView

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜