Search code examples
macosswiftinterface-buildernssplitview

Why is my split view behaving like this and how can I fix it?


I created a split view controller that displays two views, like this : enter image description here

When I compile it, it gives me this result : enter image description here

Unfortunately, the first view isn't visible and I must drag from the left hand side of the window to see the two views :
enter image description here

First, why is the split view behaving like this ? Why isn't it already at the right size from the beginning ?
If I add this line to the viewDidLoad() function of my SplitViewController :

splitView.adjustSubviews()

Then the two view appears, with equal size, but I don't understand what the adjustSubviews() function does exactly, and I can't control the position of either.

How to fix it programmatically ? How to adjust the size of each view ? Is there a way to adjust it in interface builder ?

Thank you.

EDIT : There is now a bounty of 50 points for this question


Solution

  • Since NSSplitViewController is auto-layout based, you can use auto-layout either if you want a fixed or a dynamic behavior on your views.

    For a fixed width what you can do is add a custom view inside your 2 views with a 0 constraint to all the edges and a fixed width. For example:

    enter image description here

    Then the window will get expanded as follows:

    enter image description here