2

I am writing a non-NSDocument-based application similar in style to, say, AddressBook.app. It has a single window located in MainMenu.nib.

Currently, I am struggling with integrating NSUndoManager with this application. If I create an instance of NSUndoManager and store it into an instance variable of my AppController class, the "Undo" menu item doesn't get enabled on registering undos with the manager.

What do I have to do in order to connect the NSUndoManager instance to the menu items and have it manage the window's dirty state?

4

1 回答 1

4

您可以在您的 AppDelegate 类中创建您的撤消管理器作为该类的成员。然后您将 AppDelegate 设置为界面生成器中窗口的委托。之后您在 AppDelegate 中编写此方法:

- (NSUndoManager*) windowWillReturnUndoManager: (NSWindow*) window
{
    < return the undo manager created >
}
于 2012-07-01T22:54:47.910 回答