【问题标题】:iPhone- How to get the main view (1st view) every time when we switching form one tab to another tabiPhone-每次从一个选项卡切换到另一个选项卡时如何获取主视图(第一个视图)
【发布时间】:2013-05-07 05:16:13
【问题描述】:

在我的 iPhone 应用程序中,我使用了 tabbarcontroller,因为我有 4 个选项卡用于四个不同的项目

在每个选项卡中,我都有不同的视图来导航其中的事务。

我的要求是,当我通过点击标签栏项目将标签上的表单切换到另一个标签时

T*the main view (first view ) of each tab has to be appeared instead of currently working view.*

例如:

  1. 我选择选项卡 3,在那里我执行一些操作并导航到第三个选项卡中的某个第二个视图。

  2. 然后我看到标签 4,然后又看到标签 3.. 然后之前的工作视图视图 2 出现在标签 3 中,

    1. 但是当我选择标签 3 时,我需要随时呈现第一个视图(与任何其他标签相同)

怎么办..

【问题讨论】:

  • 你在标签的第二个视图中有一个导航控制器吗?

标签: iphone objective-c uinavigationcontroller uitabbarcontroller


【解决方案1】:

创建 UINavigationController 的子类,将情节提要中的任何导航控制器的类更改为该类,并将此代码放入该子类中:

-(void)viewDidDisappear:(BOOL)animated {
    [self popToRootViewControllerAnimated:NO];
}

当你点击另一个标签时,这个方法将被调用,它会将导航堆栈重置回根视图控制器。

【讨论】:

    【解决方案2】:

    将您的视图控制器或 appdelegate 设置为您的 tabbarcontroller 的委托。实现这个委托函数

    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
      int selectedIndex = tabBarController.selectedIndex;
      NSArray *tabbarControllers = tabBarController.viewControllers;
    
      //Then replace tabbarControllers[selectedIndex] by your new view controller(with navigation controller) 
    
       tabBarController.viewControllers = Your replaced Array;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-05-21
      • 2014-07-28
      • 1970-01-01
      • 2017-01-15
      • 2017-10-31
      • 2010-12-15
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多