好的,这就是场景:
我有一个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
我该如何做到这一点?
答案 0 :(得分:2)
您需要在适当的控制器上调用pop命令,即执行以下操作:
UIViewController *selectedController = [[self tabBarController] selectedController];
[[selectedController navigationController] popToRootViewControllerAnimated: YES];