ViewController 之间的 UIActivityIndicatorView
在我的 FirstViewController 中,有一个调用 SecondViewController 的 IBAction。
ViewDidLoad
中的 SecondViewController
从服务器加载一个数组,因此 FirtsViewController
和 SecondViewController
之间的转换时间这么长。
我想在 FirstViewController 中放置一个 UIActivityIndicatorView ,当 IBAction y 按下时它将产生动画,并在视图之间的转换完成时停止。
¿一些想法?
谢谢大家。
此致
In my FirstViewController
, there is an IBAction
that call to SecondViewController
.
SecondViewController
in his ViewDidLoad
loads an array from an server, for this reason the time of transition between FirtsViewController
and SecondViewController
is so long.
I would like put an UIActivityIndicatorView
in FirstViewController
that it will animating when IBAction
y push, and stop when the transition between views is finish.
¿Some idea?
Thanks for all.
Best regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您应该异步加载数据。像这样的东西:
You should load the data asynchronously. Something like:
为此,您必须在第一个视图控制器或第二个视图控制器上添加活动指示器。
或者另一个选择是放置一个计时器来加载第二个视图控制器,如下所示,
从上面的代码行,屏幕将立即导航,然后从服务器加载数据。使用“firstAPIcall”方法。
For that you have to add activity indicator either on the firstViewController or on the secondViewController.
Or Another option is put a timer to load second view controller like this,
From the above line of code the screen will immediately navigate and and then load the data from server. Using the "firstAPIcall" method.
在单独的方法中编写服务器调用。在第二个视图控制器的 viewDidLoad 中,在后台线程上调用此服务器方法。并开始显示带有活动指示器的视图。同时,在服务器方法中,一旦调用完成,就调用主线程上的回调方法,该方法隐藏活动指示器并在第二个视图控制器上显示所需的内容。
Write the server call in a separate method. In the
viewDidLoad
of your second View controller, call this server method on the background thread. And start showing a view with an activity indicator. Meanwhile in the server method, once the call is complete, make a call to a callback method on the main thread which hides the activity indicator and display the required things on your second view controller.我建议将带有活动指示器的总体视图放在所有视图之上,这样无论呈现哪个视图,都将始终呈现活动指示器。
为此,您需要创建一个带有活动指示器的透明视图,您可以在此处阅读相关内容:
http://ramin.firoozye。 com/2009/09/29/semi-modal-transparent-dialogs-on-the-iphone/
I would recommend to put an overall view with activity indicator, above all the views so no matter which view is being presented the activity indicator will always be presented.
To do so, you need to create an transparent view with activity indicator, you can read about that here:
http://ramin.firoozye.com/2009/09/29/semi-modal-transparent-dialogs-on-the-iphone/
你可以这样做:
SecondViewController 的
viewDidLoad
中.h 文件上的
在.m 文件中的
you can do like this :
In your SecondViewController's
viewDidLoad
on .h file
in .m file