简体   繁体   English

iPhone-每次我们从一个选项卡切换到另一个选项卡时如何获取主视图(第一视图)

[英]iPhone- How to get the main view (1st view) every time when we switching form one tab to another tab

In my iPhone app, I have used tabbarcontroller in that i have 4 tabs for four different items 在我的iPhone应用程序中,我使用了tabbarcontroller,因为我有4个用于四个不同项目的标签

In each tab i have different views navigate transaction in those. 在每个选项卡中,我都有不同的视图来浏览其中的事务。

my requirement is, when i switch form on tab to another tab by taping on tabbar item . 我的要求是, 当我通过点击选项卡项来将选项卡上的表单切换到另一个选项卡时

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

For ex: 例如:

  1. I select tab 3 there i do some operations and navigate to some 2nd view in the third tab. 我选择选项卡3,然后在其中进行一些操作,然后导航到第三个选项卡中的某些第二视图。

  2. and then i secet tab 4 and then again tab3.. then the previously woriking view view 2 presents in tab3, 然后我先选择选项卡4,再选择选项卡3。然后在选项卡3中显示以前工作的视图2,

    1. But i need to present 1st view at any time when i select tab 3 (Same like in any other tabs) 但是当我选择选项卡3时,我需要随时显示第一视图 (与其他任何选项卡相同)

how to do.. 怎么做..

Make a subclass of UINavigationController, change the class of any navigation controllers you have in your storyboard to that class, and put this code in that subclass: 创建UINavigationController的子类,将情节提要中具有的所有导航控制器的类更改为该类,然后将此代码放入该子类中:

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

Whenever you click on another tab, this method will be called, and it will reset the navigation stack back to the root view controller. 每当您单击另一个选项卡时,都会调用此方法,并将导航堆栈重置回根视图控制器。

Set your view controller or appdelegate as delegate of your tabbarcontroller. 将视图控制器或appdelegate设置为tabbarcontroller的委托。 implement this delegate function 实现此委托功能

- (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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM