(Iphone Sdk) 如何在加载视图控制器时显示动画活动指示器?
我的视图非常重,需要两秒或更长时间才能加载。我想在 viewDidLoad 上携带所有内容时显示活动指示器,然后隐藏它。有人可以指导我这样做吗?提前致谢。
I have a so heavy view that takes two seconds or more seconds to load. I would like to show activity indicator while be carrying all things at the viewDidLoad and then hide it. Can someone guide me to do this? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试 Matej Bukovinski 的 MBProgressHUD。
https://github.com/matej/MBProgressHUD
在后台获取数据
如果你想在 main 中获取数据线程,只需显示 HUD,然后在收到通知时将其关闭。
Try MBProgressHUD by Matej Bukovinski.
https://github.com/matej/MBProgressHUD
Fetching data in background
If you want to get data in main thread, just show the HUD and then dismiss it when notified.
我不确定,但我怀疑是否可以在后台线程上运行 viewDidLoad 。如果这是真的,那么在运行 viewDidLoad 时,您将无法为活动指示器设置动画。
所以如果我是你,我会弄清楚是什么花了 viewDidLoad 这么长时间,并将其放入可以在后台运行的方法中。
然后在 viewWillAppear 方法中添加一个活动指示器视图,并在后台任务完成时将其删除。
根据您在 viewDidLoad 中执行的操作,这可能需要大量重构和添加委托方法。
我猜你正在下载一些应该显示的东西。
I don't know for sure but I doubt that it's possible to run viewDidLoad on a background thread. If this is true you have no way to animate an activity indicator when running viewDidLoad.
So If I were you I would figure out what takes viewDidLoad so long, and put this into a method that can run in the background.
Then add a activity indicator view in your viewWillAppear method and remove it when your background task is complete.
Depending on the stuff you do in viewDidLoad this might require a lot of refactoring and adding of delegate methods.
I guess you are downloading something that should be displayed.
尝试将花费很长时间的内容移至 viewDidAppear 中。然后,您可以使用活动指示器创建一个新视图并使其可见(在界面生成器中最简单),一旦您完成所有工作,只需调用:
祝你好运
Try moving the stuff that's taking so long into viewDidAppear. Then you can create a new view with the activity indicator and have it visible (easiest in interface builder) and once all your stuff is done just call:
good luck
将
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
放入调用慢速加载 viewController 的视图中,如果慢速启动器是初始视图,则放入 appDidFinishLoading 中。此外,请考虑将需要很长时间的活动从主线程移至后台线程,以保持 GUI 始终响应。
Put
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
in the view from where you call the slow loading viewController, or into appDidFinishLoading if the slow starter is the initial view.Additionally, consider moving the activity that takes a long time from the main thread into a background thread, keeping the GUI always responsive.
你可以非常简单地做到这一点
在 viewDidLoad
加载页面视图后,您可以通过以下方式停止对活动指示器进行动画处理
[停止动画的日期];
这会起作用
you can do this very simply
in viewDidLoad
After loading the page view, there u stop animate the Acitivity indicator by
[date stopAnimating];
this will work