2

I try to show the master of the SVC programmatically.

The app is universal. I have a TVC on the master and another TVC on the details. The cells on the detail-TVC can be deleted by the user. After the user deleted the last cell in the detail-TVC on iPhone (compact) the master should be shown. On iPad (regular) the next existing cell on the master-TVC is selected and shown (works fine!)

I tried to perform the displayModeButtonItem's action manually but nothing happens:

extension UISplitViewController {
    func toggleMasterView() {
        let barButtonItem = self.displayModeButtonItem()
        UIApplication.sharedApplication().sendAction(barButtonItem.action, to: barButtonItem.target, from: nil, forEvent: nil)
    }
}

For testing a added a "Show" button on the navigation-bar of the detail-TVC and performed the function above.

@IBAction func do_ShowMaster(sender: BaseUIBarButtonItem) {

    self.navigationController!.splitViewController?.toggleMasterView()

}

Storyboard: Storyboard Thank you in advance.

Mario
  • 978
  • 2
  • 11
  • 31
  • Works like a charm: http://stackoverflow.com/questions/27540268/ios8-uisplitviewcontroller-how-to-switch-to-master-view-in-compact-width-window?rq=1 but why is the method above not working? – Mario Aug 15 '16 at 19:38

1 Answers1

3
@IBAction func showMaster(sender: BaseUIBarButtonItem) {

    self.splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.allVisible 

}
Rohit Funde
  • 1,080
  • 1
  • 13
  • 20
  • This instantly shows or hides the master view controller. Is there a way with an animation? – Nickkk Jan 03 '23 at 13:02
  • I know this comment is old, but just in case anybody else is running into this, you have to put this line in an animation block to get the master view controller to show up animated. https://developer.apple.com/documentation/uikit/uisplitviewcontroller/1623170-preferreddisplaymode – Adam Kaump Jun 04 '23 at 19:22