以编程方式切换到另一个选项卡并切换到第一个视图控制器? [英] Programmatically switch to another tab AND switch to the first view controller?

查看:104
本文介绍了以编程方式切换到另一个选项卡并切换到第一个视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式切换到另一个标签并转到导航堆栈中的第一个视图?



我可以切换到另一个标签页。

  self.tabBarController.selectedIndex = 4; 

但是,我还需要在该选项卡的导航堆栈中切换不同的视图控制器。 / p>

我该怎么做?



一旦我运行上面的代码,它就会切换,但是导航堆栈中当前加载的视图控制器。



我的视图控制器被加载到5个导航控制器中,这些控制器被添加到app delegate中的选项卡栏。

解决方案

我假设你的 UITabBarController中有 UINavigationController s 。如果是这种情况,您可以使用 popToRootViewControllerAnimated:转到第一个视图控制器。

  int index = 4; 
self.tabBarController.selectedIndex = index;
[self.tabBarController.viewControllers [index] popToRootViewControllerAnimated:NO];


How do I programmatically switch to another tab and go to the first view in the navigation stack ?

I can switch to a different tab.

self.tabBarController.selectedIndex = 4;

However, I also need to switch the a different view controller in the navigation stack of that tab.

How do I do that?

As soon as I run the code above, it switches, but to the currently loaded view controller in the navigation stack.

My view controllers are loaded into 5 navigation controllers which are added to the tab bar in app delegate.

解决方案

I assume you have UINavigationControllers in your UITabBarController. If that's the case you can use popToRootViewControllerAnimated: to go to the first view controller.

int index = 4;
self.tabBarController.selectedIndex = index;
[self.tabBarController.viewControllers[index] popToRootViewControllerAnimated:NO];

这篇关于以编程方式切换到另一个选项卡并切换到第一个视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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