Instance Method

showDetailViewController(_:sender:)

Presents the specified view controller as the secondary view controller of the split view interface.

Declaration

func showDetailViewController(_ vc: UIViewController, sender: Any?)

Parameters

vc

The view controller to display in the secondary (or detail) location of the split view interface. If you specify nil for this parameter or if this view controller is the same as the one it would replace, this method does nothing.

sender

The view or view controller that made the request.

Discussion

Whenever possible, use this method (instead of modifying the contents of the viewControllersproperty directly) to replace the secondary view controller of your split view interface. This method displays the specified view controller in the best way possible given the current size class in effect. It also takes advantage of existing navigation controller behaviors whenever possible to minimize changes to the split view interface.

This method calls the delegate’s splitViewController(_:showDetail:sender:) method to give the delegate an opportunity to show the view controller. If the delegate does not show the view controller, the split view controller forwards the message to the view controller being replaced to see if it wants to do anything. For example, a navigation controller responds by pushing vc onto its navigation stack. If no other object wants to show the view controller, the split view controller shows it using the following heuristics:

  • In a horizontally regular environment, the split view controller installs vc as the secondary view controller.

  • In a horizontally compact environment, the split view controller presents vc modally.

All view controllers implement this method. If they do not show the view controller themselves, they forward the message to the parent split view controller (if any) and let it show the view controller. As a result, a child view controller can call this method on itself to achieve the same results as calling this method on the split view controller object.

See Also

Action Methods for Displaying View Controllers

func show(UIViewController, sender: Any?)

Presents the specified view controller as the primary view controller in the split view interface.