NSUndoManager 和启用/禁用撤消按钮
在我的 iOS 应用程序界面中,我有明确的撤消和取消操作。重做按钮(摇动撤消是一个相当重量级的操作,在这种情况下,撤消执行得非常频繁)。通常,我会使用 KVO 来观察 NSUndoManager 的 canUndo 和 canRedo 关键路径并启用 &不幸的是,NSUndoManager 对于这些关键路径似乎不符合 KVO 标准——或者至少,我没有看到任何通知方面的内容。
所以我的问题是:我如何让它发挥作用?我只是用 KVO 做错了吗? (我已经双重检查过,但总有这种可能性)。还有另一种我没有想到的方法可以做到这一点吗? (虽然我每次运行循环旋转时都会检查 -canUndo 的值,但这对我来说有一种不好的代码味道)。
(请注意,NSUndoManager 在 iOS 和 Mac OS X 上很可能是不同的,所以在这种情况下,我认为“它在 Mac 上工作”不会是一个有用的答案)
In my iOS application's interface I have explicit undo & redo button (shake-to-undo is a pretty heavyweight action and in this context, undos are performed pretty frequently). Normally, I would use KVO to observe NSUndoManager's canUndo and canRedo key paths and enable & disable the buttons as the notifications come in. Unfortunately, NSUndoManager doesn't seem to be KVO-compliant for those key paths -- or at least, I'm not seeing anything in terms of notifications.
So my question is: How do I get this working? Am I just doing it wrong with KVO? (I've double & triple checked but there's always that possibility). Is there another way to do this that I'm not thinking of? (I've though about just checking the value of -canUndo every time the runloop spins but that has kind of a bad code smell to me).
(Note that it's quite possible that NSUndoManager is different on the iOS and Mac OS X, so I don't think "It works on the Mac" is going to be a helpful answer, in this case)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注册您的 NSUndoManager 的 NSUndoManagerDidUndoChangeNotification 和朋友来检查何时创建新的撤消组并从堆栈中弹出并相应地更新按钮的状态。
Register for your NSUndoManager's NSUndoManagerDidUndoChangeNotification and friends to examine when new undo groups are created and popped off the stack and update your button's states appropriately.