8

I've got an NSSplitView and on the left side I've got a tableView (like a source list) and depending on row selection, I want to change the the right side of the split view. I can't quite figure out how to do this.

When I add my desired subview to the splitview, it adds another split (so now there's 3 views total... not what I wanted).

[mySplitView addSubview:myCustomView];

How do I properly set the right side of my splitView?

Update

Using

[mySplitView replaceSubview:[[mySplitView subviews] objectAtIndex:1] withSubview:myCustomView]

Seems to work, however it's resizing the split view rather oddly, how can I stop this? In IB there's an option to turn off autoResizesSubviews but I can't uncheck this. Any ideas?

jbrennan
  • 11,943
  • 14
  • 73
  • 115

2 Answers2

10

Try setting the frame of your new view to that of the old view before performing the swap.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • 1
    @JonF: 1. Get the frame of the old view. 2. Set the frame of the new view to that. 3. Then swap the old view for the new. – Peter Hosey Feb 01 '12 at 05:19
  • NSRect rect = [[[_splitView subviews] objectAtIndex:0] frame]; [[_tableVC view] setFrame:rect]; [_splitView replaceSubview:[[_splitView subviews] objectAtIndex:0] with:_tableVC.view]; – Newsonic Apr 04 '19 at 21:52
0

Also, you might take a look at BWToolkit which provides a much nicer way to set the sizes for the sides of a split pane.

Jon Steinmetz
  • 4,104
  • 1
  • 23
  • 21
  • I've looked in to that before, and I'll probably eventually use it. For now I want to learn how to do things the `Hard way` so I can understand them better. I find when I start off with toolkits too much of it feels like magic. After I'm comfortable, I will likely use it though. I've heard nothing but good about it. – jbrennan Sep 14 '09 at 01:01