milof
milof

Reputation: 696

How can I go to top level UINavigationController in one UITabBarController from another UINavigationController in another UITabBarController?

OK so this is the scenario:

I have a Tab bar application that has a UINavigationController in each tab. Lets say I have two tabs, "Home" and "Signout". In "Home" the user follows a UINavigation based navigation down 3 levels and presses submit. After that they click on "Signout", click on the signout button.

What I want to do is to:

Take the user back to the first tab "Home", and then do a "Pop to root navigation controller"

My code in Signout is :

[[self tabBarController]setSelectedIndex:0]; //this takes me to the first tab "Home"

[self.navigationController popToRootViewControllerAnimated:YES]; //this does not work

How do I get about doing this?

Upvotes: 3

Views: 2200

Answers (1)

jv42
jv42

Reputation: 8593

You need to invoke the pop command on the proper controller, ie do something like:

UIViewController *selectedController = [[self tabBarController] selectedController];
[[selectedController navigationController] popToRootViewControllerAnimated: YES];

Upvotes: 2

Related Questions