tags:

views:

45

answers:

2

I've got a Tab Bar, and each of the tabs' view controllers is a nav controller. If you press on a tab that is already selected, it pops the view controller back. for one the tabs, i want this not to happen. What do i make a delegate of? I tried overriding

-(UIViewController *)popViewControllerAnimated:(BOOL)animated

in the nav controller to return 0, but that doesn't stop it from popping!

A: 

You can accomplish this by subclassing UITabBarController, and setting it as the UITabBarControllerDelegate for itself.

Implement tabBarController:shouldSelectViewController:, testing whether it is selecting the view controller you are concerned about, and if it is already selected. return nil if it satisfies the above.

If you'd like, I can put together some actual code, but this should get you in the right direction.

Kelso.b
You dont need to subclass anything to accomplish this. Just set the delegate of a standard `UITabBarController`.
Squeegy
+1  A: 

user74574 is close, but you shouldn't return nil, you should return NO. Yes, technically they are both the same in term of the bits, bit types have meaning and ignoring that will (depending on the situation) result in warnings and/or bugs that could be detected via static analysis. The could you want to implement in your delegate should be something like this:

- (BOOL)tabBarController:(UITabBarController *)tabBarController_ shouldSelectViewController:(UIViewController *)viewController {
  if (viewController == tabBarController_.selectedViewController) {
    return NO;
  } else {
    return YES;
  }
}
Louis Gerbarg