6
votes

As you know, a UISplitViewController has one root controller and one detail view controller only, but I want to use another detail view controller.

When I select the list items from the root controller (popover controller), the selection should fire different detail views -- i.e., row1 fires detail view1, row2 fires detail view2 and a button item fires detail view3, etc. How can I achieve this?

4

4 Answers

6
votes

That project from Apple is from 2012 and doesn't use storyboards. If you are looking for a non-storyboarded solution, it will work fine but in Xcode 6 you should be taking advantage of the new Show Detail segue in storyboards.

Here's a quick example project that shows how to use multiple detail view controllers on the same split view by using the Show Detail segue from the Master View Controller.

5
votes

There's a project from Apple that covers exactly what you need. MultipleDetailViews

This sample shows how you can use UISplitViewController to manage multiple detail views.

The application uses a split view controller with a table view controller as the root view controller. When you make a selection in the table view, a new view controller is created and set as the split view controller's second view controller.

The root view controller defines a protocol (SubstitutableDetailViewController) that detail view controllers must adopt. The protocol specifies methods to hide and show the bar button item controlling the popover.

1
votes

In Swift

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let storyBoard = UIStoryboard(name: "Main", bundle: nil)
    let imageGalleryVC = storyBoard.instantiateViewController(withIdentifier: "ImageGallerySID") as! ImageGalleryViewController
    splitViewController?.showDetailViewController(imageGalleryVC, sender: nil)
}
0
votes

I know this is a late post as this was asked 6 years ago and active last year. But there is a way to have multiple detail views for a split view controller.

By embedding each detail controller into its own navigation controller and linking from the master view to each using the 'show detail' segue, you are able to achieve this result of switching between views by using an identifier associated and then from the master view function 'didSelectRowAt' selecting a row is where you can select which detail view you wish to see.

if indexPath.row == 0 {
    performSegue(withIdentifier: "secondView", sender: self)
}
if indexPath.row == 1 {
        performSegue(withIdentifier: "thirdView", sender: self)
    }

enter image description here