Re: Multiple Views Using One Window
Re: Multiple Views Using One Window
- Subject: Re: Multiple Views Using One Window
- From: Jaime Magiera <email@hidden>
- Date: Sat, 19 Jan 2008 03:02:49 -0500
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden