简体   繁体   中英

How do I set a Custom NSFormatter to a NSTextView?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM