2

I have a simple document-based application that simply creates a custom XML file. It uses an Outline View to navigate the XML document. When an item in the Outline View is selected a custom view is displayed as a sub view of the document view that allows the user to enter in data. On one of the views has a NSTextField. It has its "Allows Undo" flag set. I tested to ensure the undoManager is called on the NSDocument when the editing is completed. So the control seems to be bouncing through the First Responder as it should.

In the IBAction I use the ActionName so it will display correctly in the menu. Now here is the problem. Not only is the ActionName not displayed in the menu, but clicking undo doesn't reverse the action taken on the NSTextField but the action registered just before it. Is there something I overlooked when setting up undo with NSTextField?

(IBAction)textFieldChanged:(id)sender{

...some code here...

[[self undoManager]setActionName:@"Change Text"];

}

Thanks in advance, Rob

4

1 回答 1

1

文本字段是否与大纲视图(即文档的主窗口)在同一个窗口中?如果没有,您需要为该额外窗口设置一个委托,并通过返回文档的撤消管理器来响应-windowWillReturnUndoManager:。

因为您是说正在针对您的文档调用 -undoManager,所以我猜上述情况并非如此。我从来不知道一个文本字段在文档的主窗口中时不使用文档的撤消管理器并且选中了允许撤消。您是否尝试过像删除字段并重新创建它这样简单的事情?有时 IB 会做一些奇怪的事情……很有趣,当撤消/重做 Interface Builder 本身的更改时,这些问题往往会突然出现。:-)

于 2010-09-02T23:27:19.240 回答