如何将自定义NSFormatter设置为NSTextView? [英] How do I set a Custom NSFormatter to a NSTextView?

查看:122
本文介绍了如何将自定义NSFormatter设置为NSTextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSTextView,我有一个自定义的NSFormatter,它限制了字符串的长度.但是我如何在NSTextView上"[_textView setFormatter:customFormatter]"?我找不到该怎么办.
示例代码将不胜感激!

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!

推荐答案

无法将自定义NSFormatter与NSTextView一起使用. (这似乎是NSControl的省,其中NSTextField是其子类.)

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.)

但是,可以为您的文本视图的文本存储(NSTextStorage)设置一个委托,并实现-textStorageWillProcessEditing:(一种NSTextStorageDelegate的方法);在这里您可以限制用户的输入.您自定义的NSFormatter的现有代码可能会在此处进行修改.

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.

这篇关于如何将自定义NSFormatter设置为NSTextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆