Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tabBarController:shouldSelectViewController method doesn't fire

I have read the Apple docs - http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/TabBarControllers/TabBarControllers.html#//apple_ref/doc/uid/TP40007457-CH102-SW1 about creating TabBar programmatically. I want to detect the TabBar selection so I have used following delegate methods. I am not sure why but these methods don't get fired when I change the Tabs on my iPhone. Could anyone please provide some thought on what's going wrong here. It would be really helpful. Thanks.

- (BOOL)tabBarController:(UITabBarController *)tbController shouldSelectViewController:(UIViewController *)viewController
{
    if (viewController == [tbController.viewControllers objectAtIndex:3] )
    {
        // Enable all but the last tab.
        return NO;
    }

    return YES;
}

- (void)tabBarController:(UITabBarController *)tbController didSelectViewController:(UIViewController *)viewController {
    if (viewController == [tbController.viewControllers objectAtIndex:self.appTabs.count] )
    {
        //do some action
    }
}
like image 283
AlienMonkeyCoder Avatar asked Mar 28 '11 16:03

AlienMonkeyCoder


1 Answers

Did you forget to set the delegate when you created the UITabBarController?

someTabBarController.delegate = self;
like image 127
Matthias Bauch Avatar answered Sep 21 '22 00:09

Matthias Bauch