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一起使用?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)