1

What I need may be pretty basic, but I'm definitely not sure as to how to proceed (I've done that before but none of my choices seem that Cocoa-friendly).

Ok, let's say we've got 2 NSViews - one next to the other:

  • The one on the left serves as a menu.
  • The one on the right will show a NSView (from a different XIB perhaps?) depending on the selection on the menu.

GUI Outline

My questions :

  • How should I go about loading the different NSViews into the rightmost NSView?
  • How do I make sure that the subview (the one currently active) is properly resized when the window is resized?
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223

2 Answers2

2

rdelmar's solution should work, but another approach, which may be simpler, is to use an NSTabView to handle switching between the content views. You can hide NSTabView's tabs using the settings pane in interface builder, or by calling [self.tabView setTabViewType:NSNoTabsNoBorder]. I'd probably use a table view for the left side. When the user selects a row, you do something like:

-(void)tableViewSelectionDidChange:(NSNotification *)notification
{
    [self.tabView selectTabViewItemAtIndex:[self.menuTableView selectedRow]];
}

The NSTabView can/will take care of properly resizing its content views as long as you've set up its and its content views' autoresizing masks (springs and struts) properly.

Andrew Madsen
  • 21,309
  • 5
  • 56
  • 97
1

You should be able to create a custom view in IB that looks like your yellow view, and set its resizing behavior to expand in both directions with window resizing. Then, when you get your new view (by just referencing one you already have or loading a new xib), add it as a subview of the custom view, and set its frame to that of the custom view. I think that views resize their subviews by default, so it should resize correctly with the custom view.

rdelmar
  • 103,982
  • 12
  • 207
  • 218