Good day. The task is as follows: to display the Activity Indicator when you click on the Tab Bar and switch between the associated View (simpler: there is, say, 3 Tab to each of which corresponds to its own View). How and how will this be done correctly?

  • and what exactly does not work? Do you want to go to the transition or display the indicator? - Max Mikheyenko
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦

1 answer 1

You need to designate yourself a delegate for the tabbar controller.

tabBar.delegate = self; 

Declare an instance variable indicator (to have a reference to it when you need to remove an indicator)

 @property UIActivityIndicatorView *indicator; 

to embed method of this delegate

 - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { self.indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; self.indicator.center = CGPointMake(100, 100); self.indicator.hidesWhenStopped = YES; [self.indicator startAnimating]; [self.view addSubview:self.indicator]; } 

and when you need to stop just stop animating (despite the fact that hidesWhenStopped = YES )

 [self.indicator stopAnimating]; 
  • Thank. I figured out how to draw the indicator (I tried to use the MBProgressHUD library). However, I ran into the problem of calling the indicator and stopping it. I put the “start” of the indicator in the didSelectItem method (as a result, when you click on any of the Tabs, the indicator appears), however, I don’t understand where to put the “Ending”, because after calling the indicator it remains infinitely on the View. - Yume
  • depends on condition. Well, there for example, if you need to remove it after 3 seconds or when some sort of download ends - Max Mikheyenko
  • added back - Max Mikheyenko