Data Detectors in Cocoa

陌路散爱 提交于 2019-12-30 11:16:32

问题


I want to add a data detector in an NSTextField / NSTextView like in Mail (e.g. date, email, URL, etc).

Does anyone have an idea how to do this ? I think I saw it in TextEdit's source code but when I checked it was 2005's version and I can't find the new source code.

Alex


回答1:


You need to set the formatter outlet of the object. Built in formatters are NSDateFormatter and NSNumberFormatter.

You can define custom formatters by extending the NSFormatter class. There is a chapter in Aaron Hillegass excellent 'Cocoa Programming for Max OS X' on Creating NSFormatters.

To detect dates, url, email address, etc. within the body of some text, you can use the Latent Semantic Mapping Framework. It's a public API as of Leopard but there isn't a great deal of documentation for it. There is also a command line tool called lsm that would allow you to test any custom extractors you want to use. It is a C API and not integrated into Cocoa as far as I know so you'd need to wire it up yourself




回答2:


In Snow Leopard you can now enable Data Detectors in a NSTextView by simply clicking the appropriate checkbox in the IB inspector.



来源:https://stackoverflow.com/questions/2034889/data-detectors-in-cocoa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!