1

I am trying to programmatically add a NSView over a NSSplitView (to cover it). Every attempt to do this has resulted in it being added into the NSSplitview as an extra subview. Can anyone please help?

Codes:

InfoTrainView *myView = [[[InfoTrainView alloc] initWithFrame: aFrame] autorelease];
[NSBundle loadNibNamed:@"InfoTrainView" owner:myView]; 
[self.windowController.splitViewBase addSubview:myView];
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
jread1297
  • 27
  • 5
  • let NSSlipt view is A, your view is B, so are you getting another view as C ? – Anoop Vaidya Mar 19 '13 at 12:42
  • I always end up with the Splitview with an additional subview. It originally had 3 horiz. subviews, and it gets a fourth subview (view B). – jread1297 Mar 19 '13 at 13:05
  • The splitview base address from IB is self.windowController.splitViewBase. `InfoTrainView *myView = [[[InfoTrainView alloc] initWithFrame: aFrame] autorelease]; [NSBundle loadNibNamed:@"InfoTrainView" owner:myView]; [self.windowController.splitViewBase addSubview:myView]; `. I have experimented with placing the InfoTrainView at super level, but this did not work either. – jread1297 Mar 19 '13 at 13:48

1 Answers1

0

I believe you need to add your new view as a child to the NSSplitView's superview (ie. parent). This way it becomes a sibling to the NSSplitView and can cover it. Your current method makes the new view a child of the split view, which then sets itself up as splitting four ways.

NSView* parentView = [self.windowController.splitViewBase superview];
if (parentView)
    [parentView addSubview:myView];

parentView above should get you the "content view" that is the default NSView inside of an NSWindow, which IB placed the NSSplitView inside. If parentView == nil, you can try manually adding an NSView to the window first, then putting your NSSplitView inside of that.

On a side note, your question answered my own question - how to programmatically add to the views split inside of an NSSplitView! Thanks :)

Marc
  • 324
  • 1
  • 9