When does the keyWindow get created?
I thought the NSWindow would be created before the corresponding view controller’s updateView method was called (Which I call in response to awakeFromNib), however if I create an alert sheet using NSApp’s keyWindow, it does not appear correctly.
If I place a button on that view, however, and then bring up the alert when the user clicks on it, the keyWindow is defined, and the alert displays correctly (as expected).
My Application Delegate is almost completely empty.
I don’t actually want to display the alert at startup, but I do want to know when the key window is set up. 🙂
-[NSApp keyWindow]points to an existing window (e.g. a window that has already been loaded from a nib file) that is currently the key window, typically by sending it-makeKeyAndOrderFront:.When an application starts, Cocoa:
-awakeFromNibto (a subset of) the nib file objects;as described in the Resource Programming Guide.
If the nib file contains a single window, that window becomes key upon being shown provided it can become a key window, and this happens after
-awakeFromNibhas been sent.Also, the documentation for
-[NSApplication keyWindow]states that: