简体   繁体   English

如何观察对NSTextStorage的更改

[英]How to observe changes to an NSTextStorage

I have an NSTextStorage delegate imlementing textStorageDidProcessEditing: . 我有一个实现textStorageDidProcessEditing:NSTextStorage委托。 Unfortunately, the userInfo doesn't contain any details about the changes to the text. 不幸的是, userInfo没有包含有关文本更改的任何详细信息。

How can I find out what actually changed? 我如何找出实际发生了什么变化?

Ideally I'd like to know everything sent to [NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] , but just the edited range would be good enough. 理想情况下,我想知道发送到[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] ,但是仅编辑范围就足够了。

您可以编写自己的NSLayoutManager子类,然后使用addLayoutManager:将其添加到NSTextSTorage中。

您还可以使用KVO观察NSTextStorage对象的characters属性(或它的任何其他属性),然后确切地了解其中的更改

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 

使用NSTextStorage的getter方法editedRange和changeInLength。

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

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