Adaptive Split View Controller with Storyboards
Until now, the UISplitViewController was only available on the iPad. In iOS 8 the split view controller gained the ability to collapse into a single navigation controller, when we use it on the iPhone.
This is a nice addition, but there is one major pitfall, when you're using navigation controllers inside the master- and the detail pane of your split view controller. In this case the iPhone version needs only one navigation controller, but the iPad version needs two.
More precisely, when you tap an item in the master view on the iPhone you'll see a push over to the detail view using the navigation controller of the master view controller. Contrary, on the iPad the split view controller shows a new view controller in a whole new area.
Unfortunately, Apples sample code (AdaptivePhotos) doesn't use any storyboards at all, but there is a solution: Assuming you're using a table view in your master view controller you need to create two prototype cells. The first you'll actually use and another to create an extra segue.
Link your main prototype cell to your detail view controller directly and use ShowDetail as its identifier. Now Link your extra prototype to a navigation controller and assign this segue the identifier ShowDetailWithNavigationController and then set the navigation controller's rootViewController property to your detail view controller.
That is all you have to do inside your storyboard. Now we need a little bit of code inside of our table view controller to decide when to use the right segue.
First we need to overide shouldPerformSegueWithIdentifier
https://gist.github.com/uberbruns/51e8337f365b465798c1
We test if we need a navigation controller by testing if the horizontal size class of the splitview controller is .Regular. If we identify the segue that has a counter part with a navigation controller we perform that segue and return. Otherwise we let the super class decide.
Now if we prepare the segue we need to write a little bit code to find the detail view controller in case it is wrapped in a navigation controller.
https://gist.github.com/uberbruns/f56e8e90fb2967229c1a
Basically, that's it. Have fun.