Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 523
milof Avatar asked Nov 18 '25 23:11

milof


1 Answers

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

UIViewController *selectedController = [[self tabBarController] selectedController];
[[selectedController navigationController] popToRootViewControllerAnimated: YES];
like image 64
jv42 Avatar answered Nov 21 '25 12:11

jv42