开发者

(iphone) How do I show activity indicator when there's heavy UI update?

I tried to show activity indicator while heavy UI update.

My initial failed attempt was

  1. show activity indicator at view1
  2. pushViewController (creating view of this viewController takes a long time)
  3. when view1's viewDidDisappear(when pushViewController's push animation occurs), hide activity indicator

Problem was even though I did call "show activity indicator" before pushViewController, activity indicator wasn't showing because of heavy UI which occurred in creating the view of viewController which was being pushed.

I changed strategy as bellow and it works and I don't get why.

  1. pushViewController
  2. show activity indicator at viewDidLoad of viewController
  3. do the heavy UI loading at viewDidAppear and hide indicator

I was under impression the reason that the indicator didn't show up with the first method was due to heavy UI process.

Please refer to the discussion at link. (iphone) showing activity indicator before heavy ui updating

If too much UI update on queue caused delayed UI update(indicator not showing up), why the 2nd method makes a difference?

I know that viewDidLoad gets called only when view gets created.

And viewDidAppear gets called when view actually shows up on screen.(hence can be called multiple times)

But is there a fundamental difference which would explain why the 2nd ap开发者_Python百科proach of using viewDidAppear works in my situation?

And is there a UI update thread apart from the so-called main thread? Or main thread is the UI update thread?

Thank you


First I want to make sure that you're updating UIKit UI on the main thread. This is a must, you shouldn't have to specify a thread when working with UIKit, unless you say to use the main thread, but I think that would be redundant.

I would start the activity indicator in viewWillAppear. Then load everything else in viewDidLoad.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜