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.