3

I'm using Autolayout & NSSplitViewController to develop a OS X app with two split views. But every time I run the app, the split views have different size. Sometimes it shows:

enter image description here

But sometimes:

enter image description here

What I want is the left panel have a min width of 150 and an initial width of 200. The right panel have a min width of 200 and take the rest space at the initial time.

What I do are followings:

  1. Add a NSSplitViewController and set it as the window content of the NSWindowController.
  2. Resize the left panel to the width of 200(which I want to be the initial width, but it seems not working), and add a Table View to it. Then give the table view a min width constrain of 150.
  3. Add a Custom View to the right panel and give it a min width constrain of 200.
  4. Set the holding priority of the right splitViewItem to 249.
  5. Set the view outlet of the SplitViewController to the split view.

Here's my Xcode screenshot: enter image description here The code are here: https://github.com/luin/sample-NSSplitViewControlller

luin
  • 2,077
  • 2
  • 20
  • 23
  • Why did you set "min width" constraint to the right panel? Set exact 200 width constraint! – Daniyar Jun 15 '15 at 06:02
  • @Astoria I want the right panel always take the rest space when the window's width grows. If I give the right panel an exact 200 width constraint, it would keep its width unchanged when the window is resizing, which isn't I want. – luin Jun 15 '15 at 06:14
  • Sorry, I mean "left" panel. So you need your panels to be minimum 150 pixels wide, but at start your left one must be exact 200. Try to use `setFrame:`-method on view load. – Daniyar Jun 15 '15 at 06:42

0 Answers0