El *_*ato 5 cocoa nstextview swift
我有一个文本字段和一个textView.controlTextDidChange方法响应文本字段更改.但它没有回应textview的变化.
class AppDelegate: NSObject,NSApplicationDelegate,NSTextFieldDelegate,NSTextViewDelegate {
func applicationWillFinishLaunching(notification:NSNotification) {
/* delegates */
textField.delegate = self
textView.delegate = self
}
override func controlTextDidChange(notification:NSNotification?) {
if notification?.object as? NSTextField == textField {
print("good")
}
else if notification?.object as? NSTextView == textView {
print("nope")
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在Yosemite下运行Xcode 7.2.1.我做错了吗?
controlTextDidChange:是一个NSControl类的方法,它由NSTextField,但不是由NSTextView以下内容继承:
因此,NSTextView的实例无法接收上述回调.
我认为你应该textDidChange:从NSTextViewDelegate协议实现:
func textDidChange(notification: NSNotification) {
if notification.object == textView {
print("good")
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2715 次 |
| 最近记录: |