Search code examples
swiftcocoanssplitview

How to get NSSplitView splitView:shouldHideDividerAtIndex:to be called at startup?


I have implemented my delegate methods to hide the divider when a view is collapsed, which works fine. The problem is at startup, if a view is collapsed, autosave keeps it collapsed but doesn't ask me if I want the dividers hiding, so they show by default and it looks nasty.

How can I force this delegate method to be called, what are my options if there isn't a proper way of doing it, fake a window resize?

My only solution has been:

windowSplitView.subviews[0].hidden = !windowSplitView.subviews[0].hidden
windowSplitView.subviews[0].hidden = !windowSplitView.subviews[0].hidden

Solution

  • The solution is to use the same fix for a window growing in size at each launch when the title is hidden: https://openradar.appspot.com/18510665

    You have to remove the autosave name from Interface Builder (IB) and do it programatically after the window has loaded and the frames have been set:

    override func windowDidLoad() {
        super.windowDidLoad()
        //...
        splitView.autosaveName = "YourAutosaveName"
        //...
    }