cocoa - NSWindowController can't capture ESC without WebView is added to the window -
i create subclass of nswindowcontroller file->new, , "with xib user interface" option checked. create 3 new files. use interface builder add 1 view window.
and have code in mywindowcontroller.m:
- (void)keydown:(nsevent *)theevent{ nslog(@"%@", theevent); }
- first test, add 1 nsbutton, , run project.
- second test, add 1 webview(nsbutton deleted), , run project.
in both tests, window shows correctly. diffrence is:
- (nsbutton)i can see log output when press keys 'a', 'b', ..., not esc key
- (webview)i can see log output when press keys 'a', 'b', ..., and esc key well
i change nsbutton other view type, , custom view, act first case.
my qustion is:
- why can't nswindowcontroller capture esc key down in first case?
- why nswindowcontroller capture esc key down webview first responder.
- how can nswindowcontroller capture esc key without webview?
see nsresponder
canceloperation:
docs: https://developer.apple.com/library/mac/ipad/#documentation/cocoa/reference/applicationkit/classes/nsresponder_class/reference/reference.html
this method bound escape , command-. (period) keys. key window first searches view hierarchy view key equivalent escape or command-., whichever entered. if none of these views handles key equivalent, window sends default action message of canceloperation: first responder , there message travels responder chain. if no responder in responder chain implements canceloperation:, key window searches view hierarchy view key equivalent escape (note may redundant if original key equivalent escape). if no such responder found, cancel: action message sent first responder in responder chain implements it.
and if want handle esc key in nswindowcontroller
subclass define cancel:
method in it.
Comments
Post a Comment