Re: Showing a window from a second nib
Re: Showing a window from a second nib
- Subject: Re: Showing a window from a second nib
- From: email@hidden
- Date: Sat, 5 Jan 2002 18:29:51 -0800
Make AboutController be a subclass of NSWindowController instead of
NSObject, then window will already be declared as an outlet and
showWindow: will already be implemented.
Then load the nib in when you construct the controller, not in
showWindow.
Here's how I normally handle the nib-windows with controllers...
+ (id)aboutController {
static AboutController *shared;
if (shared == nil) {
shared = [[AboutController alloc] initWithWindowNibName:@"About"];
}
return shared;
}
- (void)awakeFromNib {
// do any other initialization here...
}
Then in response to the menu item that wanted to show that window, I
just do:
[[AboutController aboutController] showWindow:self];
Note, that this leaves the window controller instance around for the
duration of the app's life. You could decide to release them when the
window closes if you're worried about memory consumption.
I'd be interested to hear if other developers do this differently, but
it has been working for me.
-tw
ps. if your window is just an about box, that really has no target
methods, you don't even need to write a controller... just use
NSWindowController, and hook everything up in IB to allow a button to
close it.
On Saturday, January 5, 2002, at 05:01 PM, Brian Luft wrote:
Greetings.
I'm attempting to load my About window from a second nib. The second
nib is
called "About.nib" and contains my window and my custom class,
AboutController, as its file owner. The AboutController contains an
outlet
to the window and a function called showWindow:. My showWindow function
loads the nib and displays the window in the following fashion:
[NSBundle loadNibNamed: @"About" owner: self];
[window center];
[window makeKeyAndOrderFront: self];
(window is the outlet). My loadNibNamed is returning YES, but my window
outlet is (null) and consequently the center and makeKeyAndOrderFront
are
failing. I'm not seeing any errors in the console, either. Any ideas?
Thanks in advance. Brian