1
votes

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?

2
I tried to create a new ManagedObjectContext for the editing window, but changes are still immediately reflected even without calling [context save]. I don't know if this is a good approach or not. I'm still binding to the selection of the main ManagedObjectContext, this may make this not work as I intend. Is it possible to copy the selection from one context to another, perhaps?Nick Locking

2 Answers

1
votes

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];
0
votes

I would suggest using a transient value in the editing window. then, when the user clicks 'OK' actually assign the value.