I've got a storyboard with an NSWindowController (the storyboard entry point), whose content is an NSViewController. When the user selects a menuitem in my application, I load the storyboard and display it.
Now I want the "escape" key to close the window. I've seen several questions about this, but none that matches the behavior I'm seeing.
I subclassed NSWindowController and NSViewController, and set the controllers in the storyboard to those. I've tried every method I could find or think of, including:
override func cancelOperation(_ sender: Any?)
func cancel(_ sender: Any?)
override func keyDown(with event: NSEvent)
in the window controller, the view controller, and even a custom NSWindow subclass, but none of these methods get called. I've confirmed that viewDidLoad()
and windowDidLoad()
do get called, so my classes are getting used. They're just not getting events.
To verify my sanity, I tried inspecting the responder chain. As expected, both my custom window controller and view controller classes are in it, as is the NSWindow subclass.
Why would an NSResponder object in the responder chain not receive events?
canBecomeKey
. – Tiny Tim