Re: Newbie Q: equipping an NSDocument subclass with a window controller
Re: Newbie Q: equipping an NSDocument subclass with a window controller
- Subject: Re: Newbie Q: equipping an NSDocument subclass with a window controller
- From: Sherm Pendley <email@hidden>
- Date: Tue, 11 Oct 2005 03:27:26 -0400
On Oct 11, 2005, at 3:05 AM, email@hidden wrote:
I'm confused over how to equip an NSDocument subclass with a window
Controller, because there are conflicting requirements :
-it seems that I must put all the IBOutlets and IBActions inside
the window controller class (if I don't, at runtime the console
duly complains that I didn't)
Not true - you can put them in your NSDocument subclass if you want.
I'm going to go out on a limb here and make some educated guesses.
I'm guessing that you need multiple window controllers per document,
so you've implemented -makeWindowControllers instead of -
windowNibName in your document class. I'm also guessing that you're
creating the controllers like this:
- (void) makeWindowControllers
{
NSWindowController *c = [[[NSWindowController alloc]
initWithWindowNibName: @"Foo"] autorelease];
[self addWindowController];
}
That's all well and good, but there's a problem - when you create a
window controller with -initWithWindowNibName:, the window controller
will "own" the nib. So, outlets and actions that have been connected
to "File's Owner" in IB will be connected to the window controller,
not to the document object.
The solution is to use -initWithWindowNibName:owner: instead, and
make your document object the owner:
- (void) makeWindowControllers
{
NSWindowController *c = [[[NSWindowController alloc]
initWithWindowNibName: @"Foo" owner:self] autorelease];
[self addWindowController];
}
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden