如何从另一个UITabBarController中的另一个UINavigationController进入一个UITabBarController中的顶级UINavigationController?

时间:2011-06-16 13:46:08

标签: iphone ios uinavigationcontroller

好的,这就是场景:

我有一个Tab栏应用程序,每个选项卡中都有一个UINavigationController。假设我有两个标签,“Home”和“Signout”。在“Home”中,用户按照基于UINavigation的导航向下3级并按下提交。之后,他们点击“Signout”,点击“注销”按钮。

我想做的是:

将用户带回第一个“Home”标签,然后执行“弹出到根导航控制器”

我在Signout中的代码是:

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

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

我该如何做到这一点?

1 个答案:

答案 0 :(得分:2)

您需要在适当的控制器上调用pop命令,即执行以下操作:

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