Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Objective-C: Disable the popping of the stack when clicking the tab with a navigation controller

Let's say I have a Tab Bar Controller with a tab A. A has a navigation controller, which lets me push new views onto the stack. Right now, if I tap A on the Tab Bar, all of the elements in A's stack will pop.

Is there a nice way to disable this? I have a sequence of views that are displayed with the navigation controller that takes user input would not like all of that to be lost with a slip of the finger.

Thanks in advance, and please let me know if my question is unclear.

like image 627
Ayaka Nonaka Avatar asked Jan 20 '26 08:01

Ayaka Nonaka


1 Answers

Try setting up a delegate for your UITabBarController, and implement:

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

If the same view controller is being selected, return NO. Then the navigation stack should not change.

Note it will only be called for the same tab you are already on from iOS 3.0 on, but at this point I would only target iOS 3.0+.

like image 53
Kendall Helmstetter Gelner Avatar answered Jan 21 '26 22:01

Kendall Helmstetter Gelner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!