Reputation: 2210
I have created a custom UITabBarController
by using Martin's tutorial.
My subclass FSTabBarController
switches between view controllers, and acts normal as far as I can see.
The issue is, when I change my tabBarContoller to my subclass, It won't respond to my delegate;
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
If I change it back to UITabBarController
-when I use the default UITabBarController
- the delegates works as it should.
The custom subclass uses the below function to represent tab selection:
- (void)_buttonClicked:(id)sender
{
self.selectedIndex = [sender tag];
[self _updateTabImage];
}
Edit:
AppDelegate.h
...
@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) FSTabBarController *tabBarController;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
self.tabBarController = [[FSTabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:peopleViewController,viewController,profileViewController, nil];
self.tabBarController.delegate = self;
...
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
// not called when FSTabBarController, called when UITabBarController !!
}
Upvotes: 2
Views: 532
Reputation: 14677
OK, downloaded the sample from his site and tested. Yes you need to manually call the deleage from the subclass:
this is how you should change the buttonClicked function:
- (void)_buttonClicked:(id)sender
{
self.selectedIndex = [sender tag];
if (self.delegate) {
[self.delegate tabBarController:self didSelectViewController:self.selectedViewController];
}
[self _updateTabImage];
}
Upvotes: 3