问题
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