I am using a Universal Storyboard in Xcode 6, targeting iOS 7 and above. I've implemented a UISplitViewController
which is now natively supported on iPhone running iOS 8, and Xcode will automatically backport it for iOS 7. It's working really well, except when you launch the app on iPhone in portrait running iOS 8, the split view's detail view controller is displayed when I expected to first see the master view controller. I believed this was a bug with iOS 8 because when you run the app on iOS 7, it correctly shows the master view controller. But iOS 8 is now GM and this is still occurring. How can I set it up so that when the split view controller is going to be collapsed (only one view controller displayed on screen), when the split view controller is displayed it shows the master view controller not the detail?
I've created this split view controller in Interface Builder. The split view controller is the first view controller within a tab bar controller. Both the master and the detail VCs are navigation controllers with table view controllers embedded inside.
Best Answer
Oh man, this was causing me a headache for a few days and could not figure out how to do this. The worst part was that creating a new Xcode iOS project with the master-detail template worked just fine. Fortunately, in the end, that little fact was how I found the solution.
There are some posts I've found that suggest that the solution is to implement the new
primaryViewControllerForCollapsingSplitViewController:
method onUISplitViewControllerDelegate
. I tried that to no avail. What Apple does in the master-detail template that seems to work is implement the new (take a deep breath to say all of this one)splitViewController:collapseSecondaryViewController:ontoPrimaryViewController:
delegate method (again onUISplitViewControllerDelegate
). According to the docs, this method:Make sure to read up on the discussion part of that method for more specific details.
The way that Apple handles this is:
This implementation basically does the following:
secondaryViewController
is what we're expecting (aUINavigationController
), and it's showing what we're expecting (aDetailViewController
-- your view controller), but has no model (detailItem
), then "Return YES to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
"NO
to let the split view controller try and incorporate the secondary view controller’s content into the collapsed interface"The results are the following for the iPhone in portrait (either starting in portrait or rotating to portrait -- or more accurately compact size class):
Clear as mud.