以编程方式切换到另一个选项卡并切换到第一个视图控制器? [英] Programmatically switch to another tab AND switch to the first view controller?
问题描述
如何以编程方式切换到另一个标签并转到导航堆栈中的第一个视图?
我可以切换到另一个标签页。
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 UINavigationController
s 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屋!