Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top