Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Disable popping to root view on pressing tab bar button

I'm looking to disable the functionality of pressing my tab bar and returning to the root view in the navigation hierarchy whilst also keeping this functionality for a button in my navigation bar.

So the only way I want the user to go back to the root view is by pressing the button in the navigation bar and not by tapping the tab bar button.

I've had a look around and tried several solutions but none seem to work as they disable the functionality for both the nav bar button and the tab bar button but not just the tab bar button.

Thanks!

like image 954
ryder Avatar asked Feb 28 '15 15:02

ryder


1 Answers

A possibility would be to create a subclass of UITabBarController and to implement the UITabBarControllerDelegate protocol. Then you could implement

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

and return NO, when the particular viewController is selected again. A way to do this is is to save the recently selected item and to compare it with the currently selected one.

like image 91
croX Avatar answered Oct 29 '22 20:10

croX