简体   繁体   English

如何将自定义NSFormatter设置为NSTextView?

[英]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. 我有一个NSTextView ,我有一个自定义NSFormatter ,它限制了字符串的长度。 But how do i " [_textView setFormatter:customFormatter] " on a NSTextView ? 但我怎么“ [_textView setFormatter:customFormatter]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. 不能将自定义NSFormatter与NSTextView一起使用。 (That appears to be the province of NSControl, of which NSTextField is a subclass.) (这似乎是NSControl的省,其中NSTextField是其子类。)

However, it is possible to set up a delegate for your text view's text storage ( NSTextStorage ), and implement -textStorageWillProcessEditing: (a method of NSTextStorageDelegate ) ; 但是,它可以建立一个委托为您的文本视图的文本存储( NSTextStorage ),并实现-textStorageWillProcessEditing:的方法NSTextStorageDelegate ); this is where you could constrain your user's input. 在这里您可以限制用户的输入。 Your existing code for your custom NSFormatter might be adapted for use there. 您的自定义NSFormatter的现有代码可能会在此处使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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