如何检测 NSTextView 上的结束编辑操作,就像在 NSTextField 上一样?我无法将其视为一项行动或其代表。
3475 次
1 回答
15
您可以注册通知,例如NSTextDidEndEditingNotification.
如果你想使用委托模式,那么你应该检查NSTextDelegate协议。文档在这里。结束编辑时发送的方法是textDidEndEditing:。
NSTextView是 的子类NSText,因此最好也检查该类的文档。
例子
NSTextView有一个NSTextViewDelegate属性,您可以使用它来获得有关更改的通知。委托方法只是获取“结束编辑”通知的便捷方法,与control:textShouldEndEditing您可能从NSTextField例如 中知道的不同。
class SomeViewController: NSViewController, NSTextViewDelegate {
var textView: NSTextView!
func loadView() {
super.loadView()
textView.delegate = self
}
func textDidBeginEditing(notification: NSNotification) {
guard let editor = notification.object as? NSTextView else { return }
// ...
}
func textDidEndEditing(notification: NSNotification) {
guard let editor = notification.object as? NSTextView else { return }
// ...
}
}
于 2012-09-05T16:16:39.187 回答