Coder Social home page Coder Social logo

Comments (3)

robbdimitrov avatar robbdimitrov commented on May 30, 2024

You can use the RDVTabBarControllerDelegate method

/**
 * Asks the delegate whether the specified view controller should be made active.
 */
- (BOOL)tabBarController:(RDVTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;

To get the index of the view controller use

NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];

Another option is to subclass the tabBarController and add the custom logic and delegate methods in the subclass.

from rdvtabbarcontroller.

CavalcanteLeo avatar CavalcanteLeo commented on May 30, 2024

it WORKED properly, but i don't know if it's the best way

- (BOOL)tabBarController:(RDVTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{

    NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
    if ([tabBarController selectedViewController]  == [tabBarController viewControllers][index]){

        if ([[tabBarController selectedViewController] isKindOfClass:[UINavigationController class]]) {
            UINavigationController *selectedController = (UINavigationController *)[tabBarController selectedViewController];

            if ([selectedController topViewController] != [selectedController viewControllers][0]) {
                [selectedController popToRootViewControllerAnimated:YES];
            }
        }
/****
HERE IS THE TRICK:
*/
        if (index == 2) {
            index = 0;
            [self tabBarController:tabBarController didSelectViewController:[tabBarController viewControllers][index]];
        }
        return NO;

    }
    return YES;
}






- (void)tabBarController:(RDVTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

    NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];

    if (index < 0 || index >= [[rdv_tabBarController viewControllers] count]) {
        return;
    }

    [tabBarController setSelectedIndex:index];
}

from rdvtabbarcontroller.

robbdimitrov avatar robbdimitrov commented on May 30, 2024

It looks ok, a little lengthy, but seems fine. What happens if [tabBarController setSelectedIndex:index]; is called in the if-block after setting the index to 0?

- (BOOL)tabBarController:(RDVTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
...
    if (index == 2) {
        index = 0;
        [tabBarController setSelectedIndex:index];
    }
    return NO;
...
}

from rdvtabbarcontroller.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.