5
votes

I have a split view controller in landscape mode with two navigation controllers.

enter image description here

This collapses to a single navigation controller in portrait and the detail view controller is pushed from the master.

enter image description here

If I rotate back to landscape when the detail view controller is pushed in portrait I don't understand how to put the detail view controller back into it's own navigation controller.

enter image description here

2

2 Answers

4
votes

You should implement UISplitViewControllerDelegate. Simplest way may be to have your own MySplitViewController class and set itself as a delegate in viewDidLoad:

self.delegate = self;

First, you may want showDetailViewController to look something like:

- (BOOL) splitViewController:(UISplitViewController*)splitViewController showDetailViewController:(UIViewController*)vc sender:(id)sender
{
    if (splitViewController.collapsed)
    {
        [(UINavigationController*)splitViewController.viewControllers[0]) pushViewController:vc animated:YES];
    }
    else
    {
        self.viewControllers = @[ self.viewControllers.firstObject, vc ];
    }
    return YES;
}

That should take care of proper showing of details view in both orientations.

Next, you should implement following delegate method similar to this:

    - (UIViewController*)                splitViewController:(UISplitViewController*)splitViewController
separateSecondaryViewControllerFromPrimaryViewController:(UIViewController*)primaryViewController
{
    UINavigationController* nc = primaryViewController;
    UIViewController* detailVC = nc.viewControllers.lastObject;
    return detailVC;
}

This method is your chance to take whatever you want from primary controller and return that as detail view controller. The example code above is rather simple one, you may need to traverse through navigation viewControllers and pick all starting from specific view controller (assuming you had pushes from details view).

Anyways, it would really payoff to take some time and read: UISplitViewController class reference and especially UISplitViewControllerDelegate Protocol Reference This will be much clearer. If you want a shortcut, take a look at Xcode split view controller template project. That one should also contain hint or exact solution for your problem.

0
votes

Make the detail have its own navigation controller, like in the Master Detail template. When the split view collapses it calls showViewController on the master navigation controller and when it detects a controller of class UINavigationController it sets allow nested navigation controllers true and hides the navigation bar. This way you get to keep the detail navigation so when you rotate to landscape and separate it can use the existing navigation again.