iPhone-显示等待指示器 [英] IPhone - Show Wait Indicator
问题描述
我尝试做的事情: 如果用户按下按钮,则将加载新的视图控制器并将其推入导航控制器.
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.
新的视图控制器在其ViedDidLoad方法中进行了一些困难的数据库查询,这会导致几秒钟的时间来加载视图.
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.
如果在分配新视图之前尝试将UIActivityIndicatorView添加为我的初始视图的子视图,则在新视图加载完成后会显示指示器...
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...
我还尝试将数据库查询放入ViewDidAppear方法中,但结果相同.
I also tried to put the database querying in the ViewDidAppear Method but with the same result.
推荐答案
看看 MBProgressHUD .真的很容易实现.
主要问题是所有UI更改都必须在主线程上完成,因此所有花费相对较长时间的任务都必须在后台线程上完成.
MBProgressHUD将为您执行此操作.如果要自定义,只需更改代码即可.
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.
这篇关于iPhone-显示等待指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!