1
votes

I'm confused how to handle a split view controller on iPhones other than the 6 Plus which handles the split view controller like iPad. I want the detail view controller to be the root view controller that appears on those iPhones.

Edit

I was able to get the behavior I wanted by adding these two delegate methods. Now the split view controller collapses to the detail view controller instead of the master view controller on iPhone.

- (UIViewController *)primaryViewControllerForCollapsingSplitViewController:(UISplitViewController *)splitViewController
{
    return self.detailNavigationController;
}

- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController
{
    return YES;
}

Problem 1

I'm getting this message now in the console when I push my master view controller onto the detail view controller's navigation controller on iPhone. It works fine so I don't understand why I'm getting this message.

Unbalanced calls to begin/end appearance transitions for <MasterTableViewController: 0x7fc8d2b67220>.

Problem 2

I'm not clear on the preferred way to detect when the split view controller collapses on iPhone. I'm using the UIViewControllerShowDetailTargetDidChangeNotification notification to detect this change but I feel like there should be some kind of delegate method for this change.

1
Answer to this question stackoverflow.com/questions/25875618/… may helpVinay Jain

1 Answers

1
votes

If you have created the UISplitViewController using the default template, you will find this method in the AppDelegate file

- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController {
    if ([secondaryViewController isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)secondaryViewController topViewController] isKindOfClass:[DetailViewController class]] && ([(DetailViewController *)[(UINavigationController *)secondaryViewController topViewController] detailItem] == nil)) {
        // Return YES to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
        return YES;
    } else {
        return NO;
    }
}

When returned YES this method handles the default behavior of UISplitViewController in small screen devices, to solve your problem you have to return NO. Replace the method with the code below

- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController {
    if ([secondaryViewController isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)secondaryViewController topViewController] isKindOfClass:[DetailViewController class]] && ([(DetailViewController *)[(UINavigationController *)secondaryViewController topViewController] detailItem] == nil)) {
        // Return YES to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
        return NO;
    } else {
        return NO;
    }
}

Have a look at the documentation