0

I have a TabBarController with 2 tabs, and each of them is NavigationController with UIViewControllers.

And, when I do some action at the 1st tab, I need be able to move one of UIViews on the 2nd tab to the top of the stack.

How can I reach 2nd tab navigation stack from 1st tab?

I don't want switch to 2nd tab, only move its UIview to the top of its stack

p.s. for example,

    TabbarController
       Tab1
         NavigationController1
          ViewController1
          ViewController2
       Tab2
         NavigationController2
          ViewController3

so from ViewController3 be able to put ViewController2 to the top of the stack NavigationController1

nastassia
  • 807
  • 1
  • 12
  • 31

2 Answers2

1

From ViewController3 get reference for navigation controller embed in first tab (NavigationController1) and then try to downcast it as UINavigationController. Then just call popToRootViewController(animated:) on this navigation controller

if let navigationController = tabBarController?.viewControllers?[0] as? UINavigationController {
    navigationController.popToRootViewController(animated: true) // or `animated: false`
}
Robert Dresler
  • 10,580
  • 2
  • 22
  • 40
-1

I hope this helps you!!

self.tabBarController?.selectedIndex = 0
Abhishek Jadhav
  • 706
  • 5
  • 12