Question

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

Was it helpful?

Solution

Is the text field in the same window as your outline view (ie, the document's main window)? If not, you'll need to set a delegate for that extra window and respond to -windowWillReturnUndoManager: by returning the document's undo manager.

Because you're saying -undoManager is being called against your document, I'm guessing the above isn't the case. I've never known a text field not to use the document's undo manager when it's in the document's main window and Allows Undo is checked. Have you tried something as simple as deleting the field and recreating it? Sometimes IB does some strange stuff ... funny enough, these problems tend to crop up when undoing/redoing changes in Interface Builder itself. :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top