Reputation: 2322
I have an app (with a UITabBarController) that can reach the final payment view via two tabs, each with their own NavigationController.
(The illustration only shows the two tabs in question)
When payment is successful I want to reset both NavigationControllers and present tab 1.
If I was on tab 1 I could just use this code:
self.navigationController?.popToRootViewControllerAnimated(true)
But if I was on tab 2 that only brings me to the first viewController in navigationController in tab 2...
How can I present another tab while also resetting the NavigationController I am on (and others)?
Any help is very much appreciated. Thank you !
Upvotes: 0
Views: 527
Reputation: 847
1) Create a custom UITabBarController
or make a category that has a method called something like: completePayment()
- (void) completePayment
{
[self setSelectedIndex:n] // n is the index of your destination tab
[[[self viewControllers] objectAtIndex:m] popToRootViewControllerAnimated: YES]; // reset the stack in the current tab
}
2) trigger this method from the ViewController that the paymant is done as such:[self.tabbarController completePayment];
3) Profit!
Upvotes: 1
Reputation: 847
There are probably ways of doing this in somewhat hacky ways, but what I will suggest you is that you reconsider your flow when you ask yourself a question like this one. Each UITab is designed to hold a UINavigationView
that is self contained and independent from other UITab elements. If you force reset a tab that you are not on, you are breaking the flow and confusing the users.
So I recommend you push your Payment ViewController, wherever you need it in the app. And don't mess with other Tabs states.
Upvotes: 0