Disable tap on current Tab (UITabBarController) iPhone App
ios, iphone, uitabbarcontroller
Solution
You tried `tabBarController:shouldSelectViewController:` delegate method? I hope that should help you.
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
id currentViewController = tabBarController.selectedViewController;
return (viewController != currentViewController);
}
If all the 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);
}
For Swift 4 the delegate method looks like this:
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
return viewController != tabBarController.selectedViewController
}
Problem
Currently, Tapping on the same Tab (in which user is working), The App moves to the very first page of that Tab. I want to disable the tap event on the Tab in which user is working currently. Any Hint?