I found that you can swap the NSSplitView
from the old-style one to the new-style one inside awakeFromNib
. A sample code follows.
I assumed window
and oldSplitView
are IBOutlet
to corresponding objects within XIB, and two dummy NSViewController
s leftVC
and rightVC
are created within XIB whose view
s are connected to the left pane and right pane. Then all you have to do is:
// enable scrolling behind the tool bar, if you haven't
window.styleMask|=NSWindowStyleMaskFullSizeContentView;
// create a new-style NSSplitView using NSSplitViewController
splitVC=[[NSSplitViewController alloc] init];
splitVC.splitView.vertical=YES;
splitVC.view.translatesAutoresizingMaskIntoConstraints=NO;
// prepare the left pane as a sidebar
NSSplitViewItem*a=[NSSplitViewItem sidebarWithViewController:leftVC];
[splitVC addSplitViewItem:a];
a.canCollapse=NO;
// prepare the right pane
NSSplitViewItem*b=[NSSplitViewItem splitViewItemWithViewController:rightVC];
[splitVC addSplitViewItem:b];
// swap the old NSSplitView with the new one
[window.contentView replaceSubview:oldSplitView with:splitVC.view ];
// set up the constraints so that the new `NSSplitView` to fill the window
[splitVC.view.topAnchor constraintEqualToAnchor:window.contentView.topAnchor
constant:0].active=YES;
[splitVC.view.bottomAnchor constraintEqualToAnchor:((NSLayoutGuide*)window.contentLayoutGuide).bottomAnchor].active=YES;
[splitVC.view.leftAnchor constraintEqualToAnchor:((NSLayoutGuide*)window.contentLayoutGuide).leftAnchor].active=YES;
[splitVC.view.rightAnchor constraintEqualToAnchor:((NSLayoutGuide*)window.contentLayoutGuide).rightAnchor].active=YES;