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: Sun, 6 Jan 2002 17:59:02 -0800
Hmm... I don't have that book. I hear it's good though.
NSWindowController is as good as any subclass if you're not doing
anything special, like in an about box.
This is a simple app that has this object instantiated in MainMenu.nib.
Connect the menu item to showAboutBox:
In the nib called AboutBox, just put whatever you want in the panel...
connect the "Ok" button to the panel's performClose: action and set the
custom class of the File's Owner to NSWindowController, and connect the
window outlet to the panel.
Then everything should work fine... If you can't get it to work, let me
know and I'll put the project up on the net.
#import <Cocoa/Cocoa.h>
@interface Controller : NSObject
{
NSWindowController *aboutBox;
}
- (IBAction)showNibWindow:(id)sender;
@end
@implementation Controller
- (id)init
{
aboutBox = [[NSWindowController alloc]
initWithWindowNibName:@"AboutBox"];
return self;
}
- (IBAction) showAboutBox:(id)sender
{
[aboutBox showWindow:self];
}
@end
On Sunday, January 6, 2002, at 04:12 PM, Tom Harrington wrote:
email@hidden wrote:
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.
Heh, I see I'm not the only reader of this list who's reading Aaron
Hillegass's book right now. :-)
<snip details>
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.
I also wrote this using a controller class, mainly because that's how
this "challenge" problem was stated. I'd like to try your approach
here but I'm not sure I understand it. Obviously the nib file can be
loaded without a controller class, but if so, how would I connect the
"About..." menu item to the display of the box? I did it by setting
the menu item's "target" outlet to call a specific method in the
controller, which then sends -makeKeyAndOrderFront:self to the panel.
I'm not sure how I'd make this link without a controller.
-- Tom Harrington, Cybernetic Entomologist
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.