有没有办法查看撤消堆栈?
我正在学习撤消,并且我想要一种方法来查看 undoManager
中的撤消对象 (NSIn Vocation
s),以便我可以看到发生了什么。我在文档中看不到类似的内容,但也许有人知道一种方法。
谢谢。
I'm learning about undo, and I'd like a way to peek into the undo objects (NSInvocation
s) in the undoManager
so I can see what's going on. I couldn't see anything like this in the docs, but maybe someone knows a way.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
来了解undo相关类的内部结构。你会发现
NSUndoManager 有两个实例变量,名为 _undoStack 和 _redoStack。它的结构非常明显,因此您可以编写一个打印堆栈的小方法。我发现这对于调试撤消相关问题非常方便。
You can use
to find out about the inner structure of the undo related classes. You will find that
the NSUndoManager has two instance variables named _undoStack and _redoStack. It's pretty obvious how it's structured, so you can write a little method printing the stack. I found that quite handy for debugging undo related problems.
您使用核心数据吗? Core Data 提供自动撤消/重做支持。否则,
NSUndoManager
将有一个空堆栈。我想我对你的问题是,你为什么要查看堆栈?实际上,您实际上没有理由必须查看撤消管理器的堆栈。如果您正在寻找有关如何创建撤消操作并将其推送到堆栈上的建议,这里有一个 关于如何做到这一点的很好的概述。 Apple 关于这个主题的文档也相当不错。我特别喜欢基于调用的方法。
Are you using Core Data? Core Data provides automatic undo/redo support. Otherwise, the
NSUndoManager
will have an empty stack.I suppose my question to you would be, why do you want to look at the stack? In practice, there's really no reason you should have to look at the undo manager's stack. If you're looking for advice on how to create undo actions and push them on the stack, here's a pretty good overview on how to do that. Apple's documentation on the subject is also quite good. I'm especially fond of the invocation-based method.
您可以打印撤消管理器的
_undoStack
私有属性:基于此要点。
You can print your undo manager's
_undoStack
private property:Based on this gist.