I got an app with my custom TabBar Controller Class.
I tried to implement tabbar controller delegate method:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NSLog(@"%i",tabBarController.selectedIndex);
}
But it doesnt work. Why?
in ViewDidLoad
i write:
self.tabBarController.delegate = self;
And in .h i implement:
@interface BaseViewController : UITabBarController <UITabBarControllerDelegate>
You have said, that it's your custom TabBarController. What is the customisation you've done? If you changed the TabBar panel and replaced it with your own to use
methods manually, then you should call delegate's methods manually too.
According to the Apple's documentation:
Also check the UITabBarControllerDelegate Protocol Reference
Delegate will respond only if user interacts with its UITabBar control.
In your custom TabBarController, do not use
But use
.tabBarController returns the nearest ancestor in the view controller hierarchy that is a tab bar controller, but your custom TabBarController IS the controller you want to target, so no need to search in its hierarchy