0
votes

I have moved from UITabBar to split view on my iPad application.

The view controllers are sent by the master to the detail which puts them into a UINavigationController.

// Detail manager called when a cell is selected on the master
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:_detailViewController];

UIViewController *mainNavigationViewController = [self.splitViewController.viewControllers objectAtIndex:0];
NSArray *viewControllers = [[NSArray alloc] initWithObjects:mainNavigationViewController, detailNavigationController, nil];
self.splitViewController.viewControllers = viewControllers;

Now every time a cell on the master is selected, the navigation controller on the detail view starts from the root.

Instead I would like to have the same behavior of the tab bar controller: when you move from one tab to another, the navigation stack for each tab is maintained. And when you select two times the same tab, the navigation stack pops to the root view controller.

How to implement this in a proper way with a split view based application?

2

2 Answers

1
votes

You should make a navigation controller for each cell in the master table. When tapping a cell, you switch it accordingly. If the selected cell is tapped, you call popToRootViewController:animated: on the visible navigation controller. Of course, you have to subclass UISplitViewController to keep a reference to your navigation controllers. You would also have to create a MaterTableDelegate to tell you split VC, he should change the navcon in the detail side.

0
votes

Starting from the suggestions of Levi I implemented a working solution. To summarize:

  • Subclass UISplitViewController
  • Create on it a public reference to each UINavigationController you need
  • Inside the init of your UISplitViewController subclass initialize all the navigation controllers with their respective root UIViewControllers
  • According to your master-detail implementation, make sure that every time you select a cell in the master view, the right navigation controller (among all the one you have declared on your UISplitviewcontroller subclass) is presented on the detail view. I managed this with an NSinteger property on the detail manager (set on master cell selection) to tell it which navigation controller to present on the detail view.
  • If the same master view cell is selected twice, pop the corresponding navigation controller to root to simulate the same UITabBar behavior.

Hope this will help someone.