3

I have a split view that looks like:

| source | filter | list | detail |

I want to programmatically hide the filter so in my NSSplitView delegate I use

-(BOOL)splitView:(NSSplitView *)splitView shouldHideDividerAtIndex:(NSInteger)dividerIndex

To hide the filter section I am using

[[[[self splitView] subviews] objectAtIndex:1] setHidden:YES];
[[self splitView] adjustSubviews];

Before hiding: enter image description here After hiding: enter image description here

I have made the dividers red in my subclass to more easily see what is happening. Both dividers are still there - right next to each other, but the one on the right should disappear completely.

Is this happening because I am trying to hide a subview that is not at the edge? Perhaps it only works for index 0 and max?

How can I make this work?

Trygve
  • 1,317
  • 10
  • 27

1 Answers1

1

You probably want to just set proper position of divider:

 splitView.setPosition(splitView.bounds.width, ofDividerAtIndex: 0)

And also override another delegate method to allow collapsing your view:

    func splitView(splitView: NSSplitView, canCollapseSubview subview: NSView) -> Bool {
    //You may choose which view you allow to collapse here...
    return true
}

func splitView(splitView: NSSplitView, shouldHideDividerAtIndex dividerIndex: Int) -> Bool {
    return true
}

I created a test project for you here:

https://github.com/emankovski/CollapseSplitViews

Eugene Mankovski
  • 1,180
  • 10
  • 16
  • Thank you for this. I'll have a look at it. – Trygve Jan 18 '17 at 05:47
  • Nope - that does not affect it. I am also having a problem with the objects in the collapsed view getting their positioning constraints messed up probably because the width is going to zero. – Trygve Jan 19 '17 at 18:13