Swift – controlTextDidChange是否可以与NSTextView一起使用?

Swift – controlTextDidChange是否可以与NSTextView一起使用?,第1张

概述我有一个文本字段和一个textView. controlTextDidChange方法响应文本字段更改.但它没有回应textview的变化. class AppDelegate: NSObject,NSApplicationDelegate,NSTextFieldDelegate,NSTextViewDelegate { func applicationWillFinishLaunchin 我有一个文本字段和一个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")        }    }}

我在Yosemite下运行Xcode 7.2.1.我做错了吗?

解决方法 controlTextDidChange:是NSControl类的一种方法,它由NSTextFIEld继承,但不是由NSTextVIEw继承:

因此,NSTextVIEw的实例无法接收上述回调.

我认为你应该从NSTextVIEwDelegate协议实现textDidChange:

func textDIDChange(notification: NSNotification) {  if notification.object == textVIEw {    print("good")  }}
总结

以上是内存溢出为你收集整理的Swift – controlTextDidChange是否可以与NSTextView一起使用?全部内容,希望文章能够帮你解决Swift – controlTextDidChange是否可以与NSTextView一起使用?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1005484.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存