title: Where do I implement the UITabBarControllerDelegate?
body: <p>I have a <code>tabBar</code> that is implemented programmatically. I would like to be able to track if the user press a certain <code>tabBar</code> item (or button or whatever it's called). As far as I understand, this is done by inheriting from the <code>UITabBarControllerDelegate</code> class. </p>
  
  <p>If I implement the <code>UITabBarControllerDelegate</code> code in one of the classes that the <code>tabBar</code> items navigates to, the <code>didSelectViewController</code> method works:</p>
  
  <pre><code>@interface ExperiencesContainerViewController () &lt;ContainerProtocol, UITabBarControllerDelegate&gt;
  @implementation ExperiencesContainerViewController
  
  - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  
      NSLog(@"PRESS");
  }
  
  - (void)viewDidLoad {
      [super viewDidLoad];
  
      self.tabBarController.delegate = self;
  
  }
  </code></pre>
  
  <p>Now this works, but it works a bit too well as it triggers not only when I press the item of this particular <code>class</code> but whichever item I happen to press, even though those items navigate to a completely different class.</p>
  
  <p>I would like the <code>method</code> to trigger only when I press the <code>tabBar</code> item of this particular class. And then I guess I would replicate this pattern in the other <code>classes</code> as well and have those methods trigger only when their respective <code>tabBar</code> item is pressed. </p>
  
  <p>I read this:</p>
  
  <p><a href="https://stackoverflow.com/questions/33837475/detect-when-a-tab-bar-item-is-pressed">Detect when a tab bar item is pressed</a></p>
  
  <p>And the answer suggests that I should implement the <code>UITabBarControllerDelegate</code> in the <code>class</code> that handles the setup of the <code>tabBar</code>. I tried that but then the <code>method</code> isn't triggered. I think this has to do with the <code>delegate</code> suddenly being set to a <code>class</code> that is not associated with one of the <code>tabBar</code> items. </p>
  
  <p>Let me know if there is additional information you need or if you need to see some more code. </p>