NSSplitViewController based application almost never launches with the correct size

后端 未结 2 1395
自闭症患者
自闭症患者 2021-02-09 02:33

I have this app that uses a NSSplitViewController as the root and has a NSTabViewController connected as its detailViewController.

This app is

2条回答
  •  灰色年华
    2021-02-09 02:56

    I couldn't say for sure what's causing the problem, but one way you may be able to solve it is to add some constraints. Interface Builder doesn't allow you to constrain the default NSView instances that it inserts into the left and right panels of the split view, so you'll need to add your own. The screen-shot below is taken from your demo, but after I've done the following:

    1. Added a subview to the left split (My Content View), and pinned it's edges to the edges of its superview (the view Xcode automatically adds to the splitview)
    2. Added an explicit width constraint of 320 pixels to My Content View

    enter image description here

    When I load the app both splits are visible, the divider doesn't budge, and the window can't be resized.

    Update - a better solution

    Although constraints are one way to solve this problem, I think the root of the problem lies in a bit of unexpected behaviour in Interface Builder. When you drag an NSSplitViewController object onto the canvas, and make it the target of the window controller's content window relationship, the split-view controller's view outlet is not actually set. One consequence of this appears to be that, when you load the app, the divider will appear to be right over to one side. To resolve this, set the aforementioned view outlet to point at the split view:

    enter image description here

    I've created a demo project with a setup similar to that in the questioner's demo app.

提交回复
热议问题