Question

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 !!
}
Was it helpful?

Solution

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];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top