I had this problem.
If you are not using storyboards, setting the UITabBarController delegate to AppDelegate is the way to go. However, with Storyboards , AppDelegate has no idea where the tabBarController is at startup. You might think of subclassing tabBarController and add a delegate method:
(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { }
... would be enough. But it is annoying.
I needed to know when the user clicked the tab button. I needed to know this more, what I needed to know was that the viewController " - (void)viewWillDisappear:(BOOL)animated {} " method was running.
I decided to make my UITabBarController my delegate. It seemed silly to me, but I did the following ...
#import <UIKit/UIKit.h> @interface PlumbsTabBarController : UITabBarController <UITabBarControllerDelegate> @end
And then the following is written in my viewDidLoad method:
[self setDelegate:self]
Which allowed me to run the delegation methods of the tab bar.
Crazy or what?
Good - now I am editing this answer, because, despite the fact that everything is correct above, where the navigationController used, it is selected every time the tabBarButton touched, the tabBarButton delegate didSelectViewController will be when you try before NSLog(@"%@", viewController); only shows that you have selected the UINavigationController class?
So, the general solution, just to add extra complexity, is to subclass the UINavigationController for each viewController that you want to control (do something) when you touch tabBarButton .
It works for me anyway. And, if someone can skip the aforementioned dribbling, they can find a useful aspect - and that's enough for me - seeing how I find this site completely useful.