0

I am trying to mimick the behaviour of apps like Notes and Contacts, where when I resize the window the left split view item collapses. I can't recreate this behaviour when using a Storyboard.

If I create the NSSplitViewController in code this works fine, however if I do it via a Storyboard it doesn't work.

import Cocoa

class MainWindowController: NSWindowController {
    override var windowNibName: NSNib.Name? {
        return "MainWindowController"
    }

    override func windowDidLoad() {
        super.windowDidLoad()

//        let splitViewController = NSSplitViewController()
        let splitViewController = NSStoryboard(name: "Storyboard", bundle: nil).instantiateInitialController() as! NSSplitViewController

        let sidebarSplitViewItem = NSSplitViewItem(sidebarWithViewController: SidebarViewController())
        splitViewController.addSplitViewItem(sidebarSplitViewItem)

        let contentSplitViewItem = NSSplitViewItem(viewController: ContentViewController())
        splitViewController.addSplitViewItem(contentSplitViewItem)

        contentViewController = splitViewController
    }    
}

I can't tell if this is a bug or if there is a property I'm missing on NSSplitViewController when it comes from a Storyboard to get the collapse behaviour to work.

Code:

Code

Storyboard:

Storyboard

2 Answers2

0

There is no split view item defined in your project. When you do it in code, you are defining the holding priority, by setting the split view behaviour as a sidebar. You can do this in interface builder as well, if you don't delete the split views themselves from interface builder. However collapsing the sidebar must be done in code. Looking at the contacts application, I believe they are tracking the window size, and collapse the sidebar when it reaches a hardcoded size.

TimTwoToes
  • 695
  • 5
  • 10
0

(Answering my own question)

I received feedback from Apple about the Radar I filed for this. I can confirm the issue has now been fixed as of macOS Catalina beta 5.