1

我有一个处理撤消和重做的视图。对于特定状态,我将第一响应者从视图更改为视图的窗口。现在在这种状态下,我希望窗口委托中的 validateMenuItem: 方法检查撤消菜单项。

这在我关闭窗口时有效。但是当窗口可见时,其他一些响应者会处理撤消操作。

我的猜测是它是窗口控制器?但由于这是一个非基于文档的应用程序,我还没有手动实现一个。我必须创建一个自定义窗口控制器吗?如果是这样,最简单的方法是什么?

4

1 回答 1

2

Found the answer here: 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.

于 2013-02-26T12:48:21.670 回答