Search code examples
objective-ccocoa-bindings

Cocoa-bindings, delaying commits of editing until user clicks 'OK'


I have an editing window with several fields, all bound to the 'content' controller key of an NSObjectController, which is in turn bound to the 'selection' controller key of an NSArrayController. I also have an NSTableView, bound to the same NSArrayController, along with its selection.

In my editing window, as soon as the user leaves a textfield, the value is propagated back to the NSTableView. How do I stop the value being committed until the user clicks 'OK' in the editing window?


Solution

  • You could use a temporary NSMutableDictionary object to store the values in the editing window, and then when the user clicks 'OK' instantiate an object using the dictionary's values: i.e.:

    NSManagedObject* obj = [NSEntityDescription insertNewObjectForEntityForName:@"MyObject"                                             
                            inManagedObjectContext: self.managedObjectContext];
    
    [obj setValuesForKeysWithDictionary:tempObject];