IPhone - Show Wait Indicator

為{幸葍}努か 提交于 2019-12-08 06:13:04

问题


What I try to do: If a user is pressing a button, a new view controller is being loaded and pushed to the navigation Controller.

The new view controller is doing some hard database querying in it's ViedDidLoad Method which causes some seconds to get the view loaded.

I'm trying to show a wait indicator before the view is starting to load.

If I try to add a UIActivityIndicatorView as subview of my starting view right before the new view is being allocated, the indicator is shown AFTER the new view finished loading...

I also tried to put the database querying in the ViewDidAppear Method but with the same result.


回答1:


Have a look at MBProgressHUD. It's really easy to implement.
The main problem is that all UI changes must be done on the main thread and therefore all tasks that take a relative long time must be done on a background thread.
MBProgressHUD will do this for you. If you want to customize it, just change the code.




回答2:


The problem is that all UI changes must be performed on applications main thread. If something blocks main thread then UI changes are not applied (UIActivityIndicatorView is not shown in your case).

To solve your problem you must run loading data routines in background thread (e.g. using -performSelectorInBackground:withObject method) leaving main thread for UI.



来源:https://stackoverflow.com/questions/2423618/iphone-show-wait-indicator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!