我正在尝试让一个自定义的NSTextFieldCell (在NSOutlineView中)在按下ESC键时结束编辑,但找不到任何方法来实现这一点。我试图为NSControlTextDidChangeNotification-notification添加一个观察者,但它不会在ESC-key中触发,keyDown也不会在NSOutlineView中触发。
发布于 2011-04-30 20:42:05
Esc在NSResponder中触发-cancelOperation。您可以尝试在响应器链中的某个位置处理此问题。
发布于 2018-12-27 03:04:24
公认的答案是正确的。更详细地说:为了捕获ESC键事件,您可以覆盖NSViewController (或您正在使用的NSResponder的任何其他派生)中的cancelOperation方法。这是我的代码在Swift 4.x中的样子。
class PopUIcontroller: NSViewController, NSTextFieldDelegate {
override func cancelOperation(_ sender: Any?) {
print("trying to cancel! Here I will do stuff to handle ESC key press!")
}
}更多信息:NSWindowController can't capture ESC without WebView is added to the window
https://stackoverflow.com/questions/5840988
复制相似问题