How do I set a Custom NSFormatter to a NSTextView?

依然范特西╮ 提交于 2020-01-06 07:55:26

问题


I have a NSTextView and i have a custom NSFormatter that limits the string length. But how do i "[_textView setFormatter:customFormatter]" on a NSTextView? I can't find how to do that.
Example code would be appreciated!


回答1:


It's not possible to use a custom NSFormatter with a NSTextView. (That appears to be the province of NSControl, of which NSTextField is a subclass.)

However, it is possible to set up a delegate for your text view's text storage (NSTextStorage), and implement -textStorageWillProcessEditing: (a method of NSTextStorageDelegate) ; this is where you could constrain your user's input. Your existing code for your custom NSFormatter might be adapted for use there.



来源:https://stackoverflow.com/questions/12919786/how-do-i-set-a-custom-nsformatter-to-a-nstextview

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