Check if NSTextView has been edited

邮差的信 提交于 2020-01-06 05:48:04

问题


Is there a way to get notified when a NSTextView gets modified?. In a NSTextField I just set the target for the default sent action and works perfectly, but I don't see any sent actions on a NSTextView.


回答1:


Come on guys. Polling? Really? NSTextView inherits from NSText, which conforms to the NSTextDelegate protocol. Look it up in the docs. The method you are looking for is: - (void)textDidChange:(NSNotification *)aNotification which you can either implement in your TextView's delegate or get by registering for a "NSTextDidChangeNotification" notification.




回答2:


Subclass NSTextField and override the textDidChange method that it has.

The delegate will tell you when it will start editing and when it will finish editing. But the control itself gets the textDidChange method called on itself.

Subclass it and override the method

- (void)textDidChange:(NSNotification *)notification;

then you could set a flag that you can access externally.



来源:https://stackoverflow.com/questions/5873387/check-if-nstextview-has-been-edited

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!