iphone : How to display Activity Indicator on clicking Tab Bar?

雨燕双飞 提交于 2019-12-11 03:31:48

问题


I want to display activity indicator when user clicks on Tab Bar.

How do I do that?


回答1:


You will need to conform to the <UITabBarDelegate> protocol to be informed when a tab is pressed and then you will need to implement

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

This is to give you the hook to be able to now set the activity indicator then:

If you are referring to the indicator in the title bar at the top then the code is

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

This is used to indicate network activity and therefore should not really be used to indicate that your app is loading if it is not using the network. This could lead to people misunderstanding what your app is doing and shutting it down if they do not expect it to connect to the network.

If you are using it to indicate network activity it is normally better to start it at the time when you start using the network and then in later method where you are informed that the network is finished with you hide it again at this point.




回答2:


To show:

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

To hide:

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

Apple Docs: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html




回答3:


You should override this method:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;

You then could add this:

[spinner startAnimating];


来源:https://stackoverflow.com/questions/6732135/iphone-how-to-display-activity-indicator-on-clicking-tab-bar

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