Skip navigation.
 
mlRe: Multiple Views Using One Window
FROM : Jaime Magiera
DATE : Sat Jan 19 09:02:49 2008

On Jan 18, 2008, at 11:32 PM, Philip Bridson wrote:

> Hi everyone, I have been programming for a short while and have been 
> picking it up quite quickly but I am now stuck. I have 3 nib files, 
> one being the main window, and the other two as custom views. The 
> main window has an NSBox and Next/Cancel buttons at the bottom of 
> the window. I want to load a different view, (which are stored in 
> their own nibs), into the NSBox each time I press 'Next'. I know I 
> have to load the nib with [NSBundle loadNibNamed:name owner:_owner] 
> but how do I get that information into the NSBox of the Main Window?
>
> Any help would be greatly appreciated.


Hi Philip,

The NSBox is itself a subclass of NSView. So, you can utilize a 
combination of removeFromSuperview and addSubview. For example, you 
could bind the box  (or create a connection in IB) to a variable in 
your main controller class ("mainBox"). Connect the "Next" button to a 
method that unloads the previous subview from that box, then adds the 
next subview ("updateSubview"). Below is some example code...

NSBox *mainBox;
NSView *currentSubview;

NSView *subView1;
NSView *subView2;
NSView *subView3;

- (IBAction) updateSubview:(id) sender
{
   [currentSubview removeFromSuperview];
   currentSubview =  subViewX             // use some logic, index, etc. to 
determine the next desired subview, and copy it to the currentSubview 
variable
   [mainBox addSubview];
}

hth,

Jaime Magiera

Sensory Research
http://www.sensoryresearch.net

Related mailsAuthorDate
mlMultiple Views Using One Window Philip Bridson Jan 19, 05:32
mlRe: Multiple Views Using One Window Kyle Sluder Jan 19, 07:04
mlRe: Multiple Views Using One Window Jaime Magiera Jan 19, 09:02
mlRe: Multiple Views Using One Window Uli Kusterer Jan 19, 12:28