0
votes

I have a base ViewController with embedded NavigationController to provide a ToolBar. The ToolBar has three buttons used to call ViewControllers by segue to present the data.

enter image description here

Showing and dismissing each data ViewController bit by bit is no problem but I would like to switch between all three data presenting ViewControllers but without dismissing and reopening ViewControllers multiple times.

  1. how do I keep the ViewController 1 - 3 open when switching between VC1 - 3?
  2. How do I know if a data presenting ViewController (VC1 - 3) is already open?
  3. How do I dismiss all open ViewControllers (VC1 - 3) when VC1, VC2 or VC3 is dismissed to go back to the base ViewController?

The base ViewController is part of a TabBarController. So, I don't want to create another one for VC1 - 3. My target is to use buttons to switch between VC1, 2 and 3 but I don't know how to start. I tried to find opened ViewController using:

ViewController1 *presenter = [(UITabBarController *)self.presentingViewController viewControllers][0];

But it just tells me that the NavigationController is the presenting ViewController. But there is no way to asks for ViewControllers opened by the NavigationController. Any ideas?

Thanks!

1

1 Answers

1
votes

Okay, I think I finally understand what you're doing. You have a base view controller with a toolbar. Clicking any of the three buttons on the toolbar will present one of three view controllers. These view controllers also display a toolbar, which allows you to toggle between those three view controllers, but you want those view controllers to persist as the user switches between them. When the user is finished, they can click the back button on the navigation bar to pop all those view controllers and return to the base view controller. Is that right?

Is it necessary to for the child view controllers to use a toolbar and not a UITabBarController? The UITabBarController would maintain a reference to all three view controllers for you, and you wouldn't have to segue between them. For example, the base view controller could still have three buttons, and the buttons would pushViewController:animated: a new UITabBarController with three view controllers, and it would also choose the selected view controller depending on which button was pressed. That might make things a lot easier for you.

The reason I propose this is that I think trying to use the navigation controller to segue between those three VCs is not the right usage of a navigation controller. Segues like this are meant to convey a hierarchical relationship between these VCs, but they seem like siblings and not children of each other.