我有一个处理撤消和重做的 View 。对于特定状态,我将第一响应者从 View 更改为 View 的窗口。现在在这种状态下,我希望窗口委托(delegate)中的 validateMenuItem: 方法检查撤消菜单项。
当我关闭窗口时,这会起作用。但是当窗口可见时,其他响应程序会处理撤消操作。
我的猜测是它是窗口 Controller ?但由于这是一个非基于文档的应用程序,我还没有手动实现。我必须创建自定义窗口 Controller 吗?如果是这样,最简单的方法是什么?
最佳答案
在这里找到答案:http://www.cocoabuilder.com/archive/cocoa/307917-validatemenuitem-not-called-for-undo-menu-item.html
Configuring the Undo menu item with action 'undo:' tells the frameworks that this is the undo menu item, so it becomes one element of a standard undo UI mechanism implemented in NSWindow. Under these circumstances, the menu item (and especially its validation) isn't yours to mess with.
If you want to take implement the entire mechanism yourself, then you should use a custom action such as 'myUndo:' for the Undo menu item. That means, as far as the frameworks know, you app doesn't have (standard) undo, and the action/validation should work in the normal way.
关于cocoa - 什么响应者捕获撤消操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15084321/