首页 文章

popToRootViewController与动画,然后切换选项卡

提问于
浏览
1

我有一个带有4个视图/标签的UITabBarController . 每个视图都是UINavigationController .

如何在其中一个UINavigationControllers上使用popToRootViewController然后切换选项卡并使用动画将viewController推送到另一个UINavigationController?

所以顺序是:

在开始时,我们在Tab 1的视图中,这是一个UINavigationController . View已被推到它的根ViewController之外 .

-Tab 1
   - UINavigationController1
      - RootViewController1
      - SomeViewController1 [We are here]

-Tab 2
   - UINavigationController2
      - RootViewController2

在SomeViewController1中点击一个按钮,导致以下内容:

  • UINavigationController1弹出到其根视图控制器(带动画)

  • UITabBarController将选项卡切换到Tab2

  • SomeViewController2被推送到UINavigationController2(带动画)

所以视图看起来像这样:

-Tab 1
   - UINavigationController1
      - RootViewController1

-Tab 2
   - UINavigationController2
      - RootViewController2
      - SomeViewController2 [We are here]

3 回答

  • 1
    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];                
             }
    }
    
  • 0
    • 弹出到您当前在UITabBar控制器中显示的导航控制器上的rootview控制器

    • 以编程方式更改选项卡

    • 以编程方式在新选项卡的navigationController上推送viewController

    所有这些都应该通过应用程序委托实现文件来实现 .

    如果您需要代码,请告诉我...

  • 0

    我就是这样做的 . 我觉得它比使用与它无关的代码感染根VC要干净得多 .

    我创建了一个UINaviationControllerDelegate,用于检查UINavigationController上剩余的UIViewControllers的数量 . 如果只剩下一个,则会发布stackAtRoot通知 . 同时就在我popToRootViewController之前,我注册了一个由此通知触发的命令 . 当它被触发时,我让它协调选项卡开关并将VC推送到新选项卡的UINavigationController上 . 它立即取消注册该命令,因此除非重新注册,否则不会再次调用它 .

相关问题