简体   繁体   English

从其他任何标签的视图控制器中弹出第二个标签的根视图(默认)

[英]pop the root view(default) of second tab from the view controller of any other tab

i am having application consisting of both TabBarController and Navigation Controller.I am having two tabs as tabA and tabB. 我有同时由TabBarController和Navigation Controller组成的应用程序。我有两个选项卡,分别为tabA和tabB。 The default selecetd tab is 1(tabB) with view controller L(when the application finish its launching).Now user can navigate as :L=>M=>N=>O. 默认的选择选项卡是视图控制器L(应用程序完成启动时)的1(tabB)。现在,用户可以按:L => M => N => O导航。 View controller for tabA is x.user can navigate as:x=>y=>z. tabA的视图控制器是x.user可以导航为:x => y => z。 there is a button on the top of the z view controller which should navigate/push/pop consumer to root view controller of tabB with view controller L. z视图控制器的顶部有一个按钮,该按钮应将消费者导航/推入/弹出到带有视图控制器L的tabB的根视图控制器。

Any sugestions,thanks 有任何建议,谢谢

This shouldn't be to hard, if I understand your question correctly that is. 如果我正确地理解了你的问题,那应该不难。

The method should look something like this: 该方法应如下所示:

- (void) pop
{
    UIViewController * target = [[self.tabBarController viewControllers] objectAtIndex:1];

    [target.navigationController popToRootViewControllerAnimated: NO];

    [self.tabBarController setSelectedIndex:1];
}

I had a similar issue, but I think I found a much simpler way to deal with it. 我有一个类似的问题,但是我认为我找到了一种更简单的解决方法。 In the view controllers that the user might end up on (O or Z in initial question), I put 在用户可能最终使用的视图控制器中(最初的问题是O或Z),我把

    [self.navigationController popToRootViewControllerAnimated:NO];

In the viewWillDisappear of those VCs. 在那些VC的viewWillDisappear中。 Seems straight forward and easy. 看起来直截了当且容易。 Am I missing a reason why I wouldn't want to do this? 我是否缺少我不想这样做的原因? Like the original questioner, I always want to start at the root VC of my tab regardless of where the user left off the last time they were on that tab. 像原始提问者一样,无论用户上次在该选项卡上离开的位置如何,我总是希望从选项卡的根VC开始。

Quick update: I constructed my own version of a split view controller and adding the above line to viewWillDisappear did some undesirable things on an iPad, so I had to add a condition to check for device type (which wasn't affected by the tab bar issue anyway because both view controllers were part of the splitVC I constructed) but otherwise seems to do what I want. 快速更新:我构建了自己的拆分视图控制器版本,并将以上行添加到viewWillDisappear在iPad上做了一些不良操作,因此我必须添加条件来检查设备类型(不受标签栏的影响)无论如何都会发出问题,因为两个视图控制器都是我构建的splitVC的一部分),否则似乎可以满足我的要求。

您需要弹出到当前标签栏的根目录,然后使用tabbar控制器方法通过setSelectedIndex方法选择标签栏按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UISearchBar显示在根视图中,但不显示在选项卡栏的任何其他视图中 - UISearchBar displays in the root view but not in any other view on the tab bar 选择选项卡时弹出到根视图 - Pop to root view when tab is selected 将标签栏控制器添加到UISplitViewController的根视图? - Adding Tab Bar Controller to Root View of UISplitViewController? 无法将第二个标签栏添加到标签栏控制器视图 - Can't add a second tab bar to tab bar controller view 故事板:从子视图弹出到根视图控制器 - Storyboard : Pop to root view controller from subview 如何从导航控制器切换到选项卡控制器并使之成为根视图控制器 - How to segue from a nav controller to tab controller and make it root view controller 从视图控制器移动到标签栏控制器 - Move from view controller to tab bar controller 选项卡栏控制器位于导航控制器内,或共享导航根视图 - Tab bar controller inside a navigation controller, or sharing a navigation root view 当根控制器是一个标签栏控制器时,重置堆栈视图 - Resets the stacks view when the root controller is a tab bar controller 如何将选项卡栏添加到默认视图并使用导航控制器与其他视图通信 - how to add a tab Bar to a Default view and communicate with other views using navigation controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM