Question

I'm wanting to fire an action when you click a certain tab (say tab [index] 3) rather than show a new viewController.

I can't find a way of doing this, is there a method for this I can implement?

Was it helpful?

Solution

Try to implement – tabBarController:shouldSelectViewController: method of UITabBarControllerDelegate in such way:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    BOOL shouldSelect = YES;
    NSInteger tabToIgnore = 3;
    if ([tabBarController.viewControllers indexOfObject:viewController] == tabToIgnore) {
        shouldSelect = NO;
        [self performSpecificAction];
    }
    return shouldSelect;
}

When you initialise UITabBarController object with list of view controllers you can use simply [[UIViewController alloc] init] for index 3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top