Re: -[NSWindowController window] fails
Re: -[NSWindowController window] fails
- Subject: Re: -[NSWindowController window] fails
- From: Alexander Shmelev <email@hidden>
- Date: Fri, 28 Nov 2008 21:12:47 +0300
Hello,
I cut off code after [self window], originally it looks like following:
- (id) init
{
if (![super initWithWindowNibName:@"Dialog"])
return nil;
[self window];
// there is a lot of code here
return self;
}
I tried to call [NSWindowController window] outside init, but it fails.
Then I tried to replace NSWindowController and initWithWindowNibName
with NSObject and [NSBundle loadNibNamed:owner:] but it fails too.
I tried to use NIB 2.x instead XIB 3.x, but it still fails.
- (id) init
{
if (![super initWithWindowNibName:@"Dialog"])
return nil;
[self window];
}
On 28.11.2008, at 20:31, j o a r wrote:
On Nov 28, 2008, at 2:06 AM, Alexander Shmelev wrote:
I have NSWindowController which loads nib with following code:
- (id) init
{
if (![super initWithWindowNibName:@"Dialog"])
return nil;
[self window];
}
I use [self window] to force nib load. This code perfectly works on
Leopard(Intel), but [self window] fails if I run it on Tiger(PPC) -
code after [self window] is not executed.
You don't have any code after [self window], so that's to be
expected... ;-)
Jokes aside, you need to "return self;" at the end of the method.
You should have a compiler warning / error about that.
I also agree with Kyle that calling [self window] in init is
probably not what you want to do. It might not even be "safe". In
general you should be very careful about calling methods on self
from your initializer. Consider this as something you need to be
almost as careful and respectful around as thread safety. Before you
have returned from your initializer your object is not to be
considered fully initialized, and therefore in the general case not
"ready for action".
It's better to call "-showWindow:" on the window controller after
it's been initialized.
j o a r
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden