当用户位于另一个选项卡中时,如何在一个选项卡上弹出popToRoot? [英] How to popToRoot on one tab when the user is in a different tab?

查看:59
本文介绍了当用户位于另一个选项卡中时,如何在一个选项卡上弹出popToRoot?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带四个标签的iPhone应用程序.在选项卡1上有一个UINavigationController.用户可以在视图堆栈上深入三层.

I have an iPhone app that has four tabs. On Tab 1 there is a UINavigationController. Users can go three levels deep on the stack of views.

假设用户进入导航选项卡1的第2级,然后切换到选项卡3.是否有任何方法可以使用户按下该按钮,然后弹出该选项卡1上的导航控制器(在场景),而它们仍在选项卡3上?这样,当再次触摸Tab 1时,它们将处于根目录级别?

Let's say a user goes to level 2 of the navigation Tab 1, and then switches to Tab 3. Is there any way to make a button that a user can press that will then popToRoot that nav controller on Tab 1 (behind the scenes) while they are still on Tab 3? That way when the touch Tab 1 again they will be at root level?

我不希望每次他们触摸Tab 1时都位于根级别,只有当他们触摸Tab 3上的该按钮时,它才会将Tab 1弹出到根级别.

I don't want it to be at root level EVERY time they touch Tab 1, only when they touch that button on Tab 3 will it pop Tab 1 to root level.

推荐答案

只要有引用,就可以将消息发送到任何有效对象.如果您的应用程序委托拥有UITabBarController,并且UITabBarController中的每个视图控制器都是UINavigationController,那么您可以在应用程序中的任何位置执行以下操作:

You can send messages to any valid object as long as you have a reference to it. If your app delegate owns the UITabBarController and each view controller in the UITabBarController is a UINavigationController then anywhere in your app you can do the following:

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication].delegate;
UINavigationController *navController = [appDelegate.tabBarController.viewControllers objectAtIndex:indexOfNavController];
[navController popToRootViewController:NO];  // animation not needed but could be YES

这篇关于当用户位于另一个选项卡中时,如何在一个选项卡上弹出popToRoot?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆