对 NSTextView 的更改未到达屏幕
我有一个 NSTextView,由我自己组装的文本系统支持,按照 Cocoa 文档中文本系统概述中的“手动组装文本系统”部分的内容。它成功地将 NSTextStorage 的内容显示在屏幕上。
但当我输入时,似乎什么也没有发生——屏幕上的文本没有改变。如果我选择文本,则选择的形状表明文本已更改。如果我将文本复制并粘贴到 TextEdit 中,我什至可以看到我的编辑。如果我输入足够多的内容,我可以让它抛出异常:
NSRunStorage, _NSBlockNumberForIndex(): index (5897) beyond array bounds (5881)
天哪,这看起来像是我可以花一天的大部分时间进行调试的事情。这是怎么回事?
I have an NSTextView backed by a text system I put together myself, along the lines of the "Assembling the Text System by Hand" section in the Text System Overview in the Cocoa documentation. It successfully displays the contents of the NSTextStorage on the screen.
But when I type into it, nothing seems to happen—the text on screen doesn't change. If I select the text, the shape of the selection suggests that the text has changed. If I copy and paste the text into TextEdit, I can even see my edits. And if I type enough, I can get it to throw an exception:
NSRunStorage, _NSBlockNumberForIndex(): index (5897) beyond array bounds (5881)
Golly, this looks like the kind of thing I could spend the better part of a day debugging. What's going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您将 NSTextStorage 连接到 NSLayoutManager,如下所示:
而不是这样:
-[NSLayoutManager setTextStorage:]
上的文档表示永远不应该直接调用它,而只能覆盖它。显然就是这个原因。希望我为您节省了数小时的徒劳工作!Make sure you connected the NSTextStorage to the NSLayoutManager like this:
Instead of like this:
The documentation on
-[NSLayoutManager setTextStorage:]
says that it should never be called directly, only overridden. Apparently this is the reason. Hopefully I saved you hours and hours of fruitless work!