disableUndoRegistration is still allowing undo operations

659 Views Asked by At

I want to disable undo registration for an operation on an NSManagedObject but it still records the operation even though I explicitly call disableUndoRegistration.

Is there something obvious I am missing?

I also tried to enable/disable in the viewWillAppear and viewWillDisappear methods, respectively.

Here is some example code...

#pragma mark -
#pragma mark NotesViewControllerDelegate methods
 - (void)notesViewController:(NotesViewController *)controller didFinishWithSave:(BOOL)save
{
    if (save)
    {
        [undoManager disableUndoRegistration];
        [book setNotes:[controller getDataFromText]];
        [undoManager enableUndoRegistration];
    }
}
1

There are 1 best solutions below

0
On BEST ANSWER

You have to call [managedObjectContext processPendingChanges]; before each of the calls that disable and enable the undo registration because Core Data queues changes to be able to do optimizations.

see http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOs.html