On my storyboard, my project begins with a split view that automatically assigns my custom UITableViewController (embedded in a navigation controller) as the detail view controller (done by relationship segue). How do I access the split view controls from my custom UITableViewController so I can change the master view controller views as appropriate?
On my storyboard, my project begins with a split view that automatically assigns my
Share
UIViewController has a property
splitViewControllerthat is a reference to the split view controller the viewController is embedded inside. Since your table view controller is embedded inside a navigation controller, which is itself embedded inside a split view controller, you first need to get a reference to the nav controller, and then from that get its reference to the split view.So in your custom tableViewController’s code you can do this:
The from that you can get a reference to your masterViewController. The splitViewController has a property
viewControllerswhich is an NSArray of two elements. The element at index zero is the master viewController. The element at index 1 is your detail view controller.Note that if your master is a custom viewController subclass (which it probably is) you should cast it as such when you pull it out of the array.
If you want to relace the master view controller with a new viewController entirely, you can do that by creating a new array with your new master VC and the existing detail view controller and assigning it to your split view controller’s
viewControllersproperty: