Re: NSDocument:windowControllerDidLoadNib && When are outlets connected to te loaded nib?
Re: NSDocument:windowControllerDidLoadNib && When are outlets connected to te loaded nib?
- Subject: Re: NSDocument:windowControllerDidLoadNib && When are outlets connected to te loaded nib?
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 16 Aug 2002 12:01:51 -0400
on 02-08-16 10:52 AM, Gerben Wierda at email@hidden wrote:
>
I have a subclass of NSDocument and NSWindowController. Now, I seem to
>
have messed things up. Because windowControllerDidLoadNib is never
>
called. Who is responsible for calling this method? Am I myself (in
>
makeWindowControllers)?
If you implement windowControllerDidLoadNib, as you did, it is called
automatically by Cocoa when the window controller loads the nib file. You
don't call it yourself.
The pattern of your makeWindowControllers method doesn't look right. You
never initialize super (NSWindowController), but only initialize your
subclass of NSWindowController, so Cocoa never gets a chance to set up
NSWindowController's private instance variables properly. That probably
prevents it from loading the nib file.
In my makeWindowControllers method, I simply call [[MyWindowController
alloc] init]. Then, in MyWindowController, I write its init method on this
standard Cocoa initializer pattern:
- (id)init {
if (self = [super initWithWindowNibName:@"MyDocument"]) {
// set my iVars and do other stuff here
}
return self;
}
If doing it my way doesn't solve your problem (I think it will), check
whether your makeWindowControllers method is being called. If not, then the
nib file is never loaded and windowControllerDidLoadNib won't be called.
makeWindowControllers is called by Cocoa's NSDocumentController open...
Commands, according to the documentation, which means, for example, in
response to the File > Open menu item among others. You can also call it
yourself in appropriate circumstances, but you normally shouldn't have to.
By the way, you need to add a [_cachedWindowController release] line at the
end of makeWindowControllers. You allocated it, which retained it. Then you
added it to the document's windowControllers array, so the array retained
it, too, as arrays always do. You're supposed to release objects after
adding them to an array or other collection, unless you have some specific
reason to need to retain ownership of it (and then you still have to release
it whenever you're through with it, certainly by the time you close the
document). Normally with window controllers, you don't need to keep
ownership of a window controller, because Cocoa only needs it in the array
(to keep the window's title in sync with save as operations, and so on). If
you don't release it, you have a big memory leak that accumulates every time
you open and close another window. But this shouldn't have caused the
problem you're experiencing.
Somebody correct me if I'm wrong.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
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.