4

I need to know evertime a certain tab on my tabbar is selected to be able to set a certain BOOL. viewDidLoad does net get called every time/when I click on the tab - is there an alternative to that?

I need to know this in that tab's-view's viewcontroller.

Pangolin
  • 7,284
  • 8
  • 53
  • 67
  • See [this](https://stackoverflow.com/questions/33837475/detect-when-a-tab-bar-item-is-pressed) or [this](https://stackoverflow.com/a/47861294/3681880) – Suragch Dec 18 '17 at 02:29

2 Answers2

4

You probably want one of these:

  • The UITabBarDelegate method - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

  • The UITabBarControllerDelegate method - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

Simon Goldeen
  • 9,080
  • 3
  • 36
  • 45
0

The UITabBar does not load all the view controllers at once - it loads the first one. When you click on a tab bar button you load another controller.

To receive the changes in the tab bar you can add a delegate and implement:

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {...}
Teodor Kostov
  • 313
  • 1
  • 11