6

According to documentation on NSSplitViewControllers, the associated NSSplitView uses the NSSplitViewController as its delegate. Specifically in the documentation, "The split view controller serves as the delegate of its split view object (the object that manages the dividers). If you override a split view delegate method, your override must call super."

I have implemented an NSSplitViewController in interface builder and gave it a class. However, none of the splitView delegates are ever invoked. Additionally, if I just do something like spit who the splitView delegate [ NSLog (@"%@", self.splitView.delegate); ], the result is "null". If, however, I assign the delegate either in IB itself (by dragging the delegate outlet to the NSSplitViewController) or inside code ([self.splitView setDelegate:self];), I get the following error:

An uncaught exception was raised
SplitViewController's splitView is unable to use autolayout because the SplitViewController overrides an incompatible delegate method.

I'm completely flummoxed.

Joe Bennett
  • 197
  • 2
  • 8

2 Answers2

20

If the delegate of a split view implements one of the following methods, it becomes incompatible with auto layout.

splitView:constrainMinCoordinate:ofSubviewAt:
splitView:constrainMaxCoordinate:ofSubviewAt:
splitView:resizeSubviewsWithOldSize:
splitView:shouldAdjustSizeOfSubview:

https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKitOlderNotes/#10_8AutoLayout


And because NSSplitViewController requires the use of auto layout (mentioned in the documentation), these methods are incompatible with NSSplitViewController and shouldn't be implemented in a subclass.

Taylor
  • 3,183
  • 17
  • 18
  • 2
    THANK YOU! I was originally incredibly confused about this as I thought the only options were low (250) and high (750), and when I did that, I did not get the behavior I was expecting. By changing subview 0 holding pattern to 260 and leaving subview 1 holding pattern at 250, I got exactly what I was trying to do. Much appreciated! – Joe Bennett Nov 19 '14 at 21:40
  • Thanks! This information is not written in the documentation anywhere! – b123400 Feb 16 '15 at 09:18
0

Extending on Taylor's answer.

In macOS 10.8 Apple made improvements to NSSplitview, which includes respecting constraints of the subviews. Apple also introduced holding priority for subviews of NSSplitview. Holding Priority is the priority of holding the size of the subview, so while resizing the splitview, subview with the lowest priority will resize first.

So to control the resizing behavior you will have to tune the holding priority of SplitView Items. This can also be done in storyboard directly

Kaunteya
  • 3,107
  • 1
  • 35
  • 66