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: Gerben Wierda <email@hidden>
- Date: Fri, 16 Aug 2002 21:01:13 +0200
On Friday, August 16, 2002, at 06:01 , Bill Cheeseman wrote:
Thanks for your answer.
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.
Well, that is my problem. windowControllerDidLoadNib is not called.
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.
No, that is not it. The nib file is loaded fine, the application works
fine. The code I showed was from my NSDocument subclass. I should not
initialize the super from my NSWindowController subclass there. In my
NSWindowController subclass I have (the second one just to be able to
see that it is called)
- (id) initWithWindow:(NSWindow *)window
{
[super initWithWindow:window];
// My code
return self;
}
- (id)initWithWindowNibName:(NSString *)windowNibName
{
[super initWithWindowNibName:windowNibName];
NSLog( @"initWithWindowNibName");
return self;
}
As initWithWindow:(NSWindow *)window is the designated initializer it is
called (it is). And I checked: initWithWindowNibName is called as well.
Strangely enough, windowControllerDidLoadNib, is not called, so there
must be something else wrong.
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;
}
That is what I already do.
If doing it my way doesn't solve your problem (I think it will), check
whether your makeWindowControllers method is being called.
Yes, it is called fine.
By the way, you need to add a [_cachedWindowController release] line at
the
end of makeWindowControllers. You allocated it, which retained it.
No. I release it when I deallocate my NSDocument subclass (this was a
problem I did have a while back though, but I decided to do it orderly,
i.e. in dealloc.
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).
It is a matter of taste, I agree that during the lifetime of my
NSDocument subclass the retain count is one higher than strictly
necessary. I had it your way first, but decided afterwards to do all my
retain bookkeeping in one place (dealloc). I might go back to the
original, though.
Which still doesn't get me closer to an answer on why
NSDocument:windowControllerDidLoadNib is not called whil the nib is
loaded fine and the app works fine too. Later in life in the app, all
connections are available.
Could you (or someone else) put a breakpoint in
YourNSDocument:windowControllerDidLoadNib and tell me what the call
stack is/should be?
G
_______________________________________________
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.