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
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 mails | Author | Date |
|---|---|---|
| Philip Bridson | Jan 19, 05:32 | |
| Kyle Sluder | Jan 19, 07:04 | |
| Jaime Magiera | Jan 19, 09:02 | |
| Uli Kusterer | Jan 19, 12:28 |






Cocoa mail archive

