Re: -[NSWindowController window] fails
Re: -[NSWindowController window] fails
- Subject: Re: -[NSWindowController window] fails
- From: Alexander Shmelev <email@hidden>
- Date: Fri, 28 Nov 2008 20:24:48 +0300
Hello,
1) I tried to load nib outside class using [NSBundle
loadNibNamed:@"Dialog" owner:theDialog], but it loads window only when
called twice.
@interface Dialog : NSObject {
}
@end
...
@interface AppController {
Dialog* theDialog
}
- (void)foo;
@end
- (void) foo
{
if (!theDialog) {
theDialog = [[Dialog alloc] init];
if (![NSBundle loadNibNamed:@"Dialog" owner:theDialog]) {
fprintf(stderr, "failed to load nib");
}
}
[theDialog showWindow:self];
...
}
If I call foo first time, loadNibNamed fails and [theDialog
showWindow:self] not called, when I call foo second time, loadNibNamed
works almost as expected (except calling File's Owner awakeFromNib)
2) I call [self window] inside to force load nib immediately.
On 28.11.2008, at 19:13, Kyle Sluder wrote:
On Fri, Nov 28, 2008 at 5:06 AM, Alexander Shmelev
<email@hidden> wrote:
- (id) init
{
if (![super initWithWindowNibName:@"Dialog"])
return nil;
[self window];
}
1) You never set self. Inside an initializer, you must always set
self to the result of the calling super's designated initializer.
2) Why are you calling -window inside -init? The whole point is that
the window controller doesn't load the nib until necessary (lazy
loading).
--Kyle Sluder
_______________________________________________
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