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. :)
When does the keyWindow get created?
-[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:
-awakeFromNib to (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 -awakeFromNib has been sent.
Also, the documentation for -[NSApplication keyWindow] states that:
This method might return
nilif the application’s nib file hasn’t finished loading yet or if the receiver is not active.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With