问题描述
我有一个带有 4 个视图/选项卡的 UITabBarController.每个视图都是一个 UINavigationController.
I have a UITabBarController with 4 views/tabs. Each view is a UINavigationController.
如何在这些 UINavigationControllers 之一上 popToRootViewController 然后切换选项卡并将 viewController 推送到另一个 UINavigationController 上使用动画贯穿始终?
How can I popToRootViewController on one of these UINavigationControllers then switch tabs and push a viewController onto another UINavigationController using animation throughout?
所以顺序是:
开始时,我们在 Tab 1 的视图中,这是一个 UINavigationController.一个视图被推到它的根视图控制器之外.
At start we are in Tab 1's view which is a UINavigationController. A View has been pushed onto it beyond its root ViewController.
-Tab 1
- UINavigationController1
- RootViewController1
- SomeViewController1 [We are here]
-Tab 2
- UINavigationController2
- RootViewController2
在 SomeViewController1 中点击一个按钮会导致以下情况:
A button is tapped in SomeViewController1 that causes the following:
- UINavigationController1 弹出到其根视图控制器(带动画)
- UITabBarController 将 tab 切换到 Tab2
- SomeViewController2 被推送到 UINavigationController2(带动画)
所以视图看起来像这样:
So the view looks like this:
-Tab 1
- UINavigationController1
- RootViewController1
-Tab 2
- UINavigationController2
- RootViewController2
- SomeViewController2 [We are here]
推荐答案
int tabYouWantToSelect=2;
BOOL isNavigation=YES;
[[self.tabBarController selectedViewController].navigationController popToRootViewControllerAnimated:YES];
//if any controller is presented as a model view then
//[[self.tabBarController selectedViewController] dismissModalViewControllerAnimated:YES];
[self.tabBarController setSelectedIndex:tabYouWantToSelect];
//the newly pushed view controller's viewWillAppear
-(void)viewWillAppear:(BOOL)animated {
if(isNavigation){
[self.navigationController pushViewController:objAddLocation animated:YES];
}
}
这篇关于popToRootViewController 带动画然后切换选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!