I think I’ve done my homework here.
I want my app delegate to be the delegate for my UITabBarController.
Using IB, I’ve connected UITabBarController‘s delegate to my Application Delegate.
App Delegate Header file is:
@interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
The delegate method I’m trying to implement is:
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
NSLog(@"shouldSelectViewController called.");
// do some stuff with viewController
return YES;
}
My app delegate has an outlet to the UITabBarController that’s connected in IB. When I do this:
NSLog(@"tab bar controller delegate is %@", self.tabBarController.delegate);
I get a good result such as tab bar controller delegate is <MyAppDelegate: 0x6e86a30>.
What am I missing?
Ok, found the solution. I had some old code in my
RootViewControllerthat set up this controller as the delegate. No delegate methods were implemented on theRootViewController, so it appeared as if nothing was happening. Because theRootViewControlleris set as delegate AFTERMyAppDelegate, the delegate was actually set to theRootViewController.So the lesson is double-check your code to make sure some other object isn’t also being set as the delegate.