Core Data : How force end editing of new object before Undo?
Core Data : How force end editing of new object before Undo?
- Subject: Core Data : How force end editing of new object before Undo?
- From: Jerry Krinock <email@hidden>
- Date: Thu, 01 Dec 2011 05:17:32 -0800
App has an NSTableView; each row represents a managed object in NSPersistentDocument.
• User inserts a new object.
• Object is inserted with -[NSEntityDescription insertNewObjectForEntityForName::].
• New row appears in the table.
• New row's "Name" column field editor becomes first responder, showing "untitled".
• But instead of entering a name, user hits ⌘Z to Undo.
• Core Data deletes new object with -[NSManagedObjectContext deleteObject:].
• Row disappears.
• User hits ⌘W to close the document.
Result:
Cocoa Error 134130 with underlying exception: "Cannot update object that was never inserted". In error's info, affected object is that new object.
I can fix this problem by overriding my undo manager's -undo and sending the window controller an -endEditing before invoking super. But this requires a little poking around to get from the undo manager to the window controller, which looks like a kind of layer violation, that is, I'm fighting Cocoa.
What is the correct way to make sure that editing is ended before undoing?
Thank you,
Jerry Krinock
P.S. In some of Apple's Core Data sample code, I see that they create a mini undo manager for a "New Object" sheet. I don't have a sheet, just a table view, and only one undo manager for my document. Wrestling with one undo manager in a Core Data document is enough for me and I am loathe to make more of them. But should I?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden