On 13 Jun 2012, at 22:50, Quincey Morris wrote: > On Jun 13, 2012, at 14:15 , Robert Tillyard wrote: > >> Window is created from a XIB using: >> >> - (id)initWithManagedObjectContext:(NSManagedObjectContext *)inMoc >> { >> if ((self = [super initWithWindowNibName:@"RunnersWindow" owner:self])) >> [self setManagedObjectContext:inMoc]; >> >> return (self); >> } >> >> - (void)windowDidLoad >> { >> [window setAutorecalculatesKeyViewLoop:NO]; >> NSLog (@"windowDidLoad: Window = %@\n", window); >> } > >> I'd still like to fix my window == NULL problem > > > You're referring to a "window" instance variable that NSWindowController does > not define, so I assume you defined it yourself. If so, that's a mistake. > You're supposed to refer to the "window" property -- self.window. > > In IB, when you connect what looks alike a "window" outlet, you're actually > connecting the NSWindowController's private "_window" ivar (or perhaps, these > days, it's connecting the "window" property, I don't know). That means your > separately-defined "window" ivar won't get connected and will always contain > nil. You should get rid of this ivar from your subclass. > > The other difficulty you're running into is that by design the window is not > created immediately when you create a window controller. (You say of your > code, above, that it creates a window from a XIB. It doesn't. It only creates > a window controller.) > > Instead, the window is created the first time something refers to the window > controller's "window" property (e.g. 'self.window' if it's referred to from > within the window controller itself). At that point, the NIB is instantiated, > the window created, and 'windowDidLoad' is invoked.
Thanks to Ken, Dennis and Quincey. I had an instance variable IBOutlet NSWindow *window in the header file that was shadowing the property. Everything is working now. Thanks everyone for taking the time to help. Regards, Rob. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com