Why does my shared view behave this way and how can I fix it?

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

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

Unfortunately, the first view is not visible, and I have to drag it on the left side of the window to see two views:
enter image description here

First, why does this separation look like this? Why is it not in the right size from the start?
If I add this line to the viewDidLoad () function of my SplitViewController:

splitView.adjustSubviews() 

Then two views with the same size appear, but I don’t understand what the adjustSubviews () function does, and I can’t control the position.

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

Thanks.

EDIT: now for this question there is a generosity of 50 points

+5
source share
3 answers

Since the NSSplitViewController is based on automatic layout, you can use automatic layout if you want your views to be fixed or dynamic.

For a fixed width, you can add a custom view inside your 2 view with a limit of 0 to all edges and a fixed width. For instance:

enter image description here

Then the window will expand as follows:

enter image description here

+7
source

You should be able to set the position of the separator in split mode (using 2 views in split mode):

self.splitView.setPosition(200.0, ofDividerAtIndex: 0)

This will set the first delimiter at position 200.0

+1
source

We need to directly set the sizes of the NSSplitView . Setting up with splitViewItems seems inefficient.

 // NSSplitViewController - (void)viewDidLoad { [super viewDidLoad]; NSView *view1 = self.splitView.subviews[0]; NSRect rect = view1.frame; rect.size.width = 150; view1.frame = rect; NSView *view2 = self.splitView.subviews[1]; rect = view2.frame; rect.size.width = 300; view2.frame = rect; } 
0
source

Source: https://habr.com/ru/post/1209006/


All Articles