Programmatically switch to another tab AND switch to the first view controller?

后端 未结 3 1054
无人共我
无人共我 2020-12-22 12:28

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.tabBarContro         


        
3条回答
  •  囚心锁ツ
    2020-12-22 13:08

    Know this is an old one, but I was faced with a similar problem. I have 3 tabs in a tabViewController, each tab has a Navigation tree that can be drilled through. When a user switches tab, I need the rootviewcontroller of that tab presented. My solution was to add the following lines to those view controllers in the Navigation trees:

        -(void)viewWillDisappear:(BOOL)animated
        {
           [super viewWillDisappear:YES];
            DLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));
           [self.tabBarController.viewControllers[self.tabBarController.selectedIndex] popToRootViewControllerAnimated:YES];
    
         }
    

    If the user is in any of the views with the above code and switches tabs, the tab they left is popped to the root view, so when they come back everything is cool....

提交回复
热议问题