清除事件我有一个视图控制器与链接到一个IBAction为一个NSButton假设perform()
。该按钮与返回键相同。 不过返回键也被用在了其他临时措施。在没有涉及到以前的视图控制器的其他文件,我有一个的NSTextField这是可编辑的,所以返回键将验证文本更改。如何在斯威夫特
我想验证我的文字兵不血刃perform()
从功能等效键按钮调用。
目前我发现的唯一解决方案是发送通知textIsBeingEditing
当我的文本字段成为FirstResponder和其他代理函数controlTextDidEndEditing
时。
这是我通知的选择:
@objc func trackNameIsBeingEditedNotification(_ notification: Notification) {
guard let value = notification.userInfo?["trackNameIsBeingEdited"]
as? Bool else {
return
}
if value {
backButton.keyEquivalent = ""
backButton.action = nil
} else {
myButton.keyEquivalent = "\r"
myButton.action = #selector(self.perform(_:))
// Here the `perform()` function is fired but I would avoid this behaviour…
}
}
没有任何办法取消键事件,以防止perform()
被解雇就在我设置myButton.action = #selector(self.perform(_:))
? 我看到一个函数flushBufferedKeyEvents()
,但我完全不知道如何使用它
继续[在Swift中取消键盘事件](https://stackoverflow.com/questions/46401695/cancel-key-event-in-swift?noredirect=1#comment79769275_46401695) – Willeke