Disable access to current app (UITabBarController) iPhone App

At the moment, clicking on the same tab (in which the user is working), the application is moved to the first page of that tab.

I want to disable the click event on the tab the user is currently working in.

Any hints?

+3


source to share


2 answers


Have you tried the tabBarController: shouldSelectViewController: delegate method ? Hope this helps you.

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

    id currentViewController = tabBarController.selectedViewController;
    return (viewController != currentViewController);
}

      



If all view controllers of the tab bar controller are UINavigationControllers, you should do it like this.

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

    id nextVC = [(UINavigationController *)viewController topViewController];
    id currentVC = [(UINavigationController *)tabBarController.selectedViewController topViewController];
    return (nextVC != currentVC);
}

      

+13


source


as below it will work



- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
    {
        if(self.tabBarController.selectedIndex==[[self.tabBarController viewControllers] indexOfObject:viewController])
            return  NO;   
        else
            return YES;
    }

      

0


source







All Articles