0

I'd like to override the animation of popToRootViewControllerAnimated: (currently: YES) when a user taps on the same tab bar item that is already selected.

When the tab bar item is first tapped, I check whether the user is signed-in in the viewWillAppear: method of the tab bar item root view controller and if not, immediately push the sign-in controller with animation disabled.

controller.navigationItem.hidesBackButton = YES;
[self.navigationController pushViewController:controller animated:NO];
[controller release];

When the user successfully signs-in, I pop back to the root controller, [animation is] no problem:

[self.navigationController popViewControllerAnimated:YES];

However, the default behavior when tapping the current tab bar item again appears to make the following calls:

-[UITabBarController _tabBarItemClicked:]

which calls

-[UINavigationController popToRootViewControllerAnimated:]

I can't tell if YES is passed into that last one, but assume so based on observation. If the user doesn't sign-in but taps the tab bar item again, it looks like the same [sign-in] controller is getting pushed/popped with animation since the viewDidLoad of the root controller just pushes the sign-in controller again. I'd like the animation to be NO in this one case.

To add to my problems, there are other navigation stacks where the sign-in controller can be pushed and it is appropriate for taps on its tab bar item to pop to the root controller. I have implemented UITabBarControllerDelegate protocol and tabBarController:shouldSelectViewController: in the sign-in controller to check if the tapped bar item root controller is the same and if that controller is the class of the controller I want to special case, but it seems inelegant. Not only that, but now the sign-in controller must know about the class of a controller that could push it onto the navigation stack. While I can keep using the protocol method, there must be a better way to do this.

Thanks for your input and ideas!

soob
  • 1,085
  • 1
  • 7
  • 9

1 Answers1

1

I think the best solution to this problem would be presenting a modal view controller when the tab bar button is selected, and then returning NO. From the delegate method.

Sam
  • 2,579
  • 17
  • 27