Question

I have a custom NSCell (actually subclassing NSTextFieldCell), which is used both in a standalone editor, and in an NSTableColumn (bound to Core Data through NSArrayController). When the user changes the value, I call -[NSCell setObjectValue:] to update the value (it's an NSNumber). This works in the standalone editor, since when it's done I manually update the binding on it.

[self setObjectValue:[NSNumber numberWithInt:newValue]];

That step (updating the bound field) is missing when the cell is in an NSTableView - the updated value shows up while the user's editing (with mouse tracking), but as soon as that's over, the value snaps back to the persisted value.

The NSTableColumn is bound to a key of -[NSArrayController arrangedObjects]. Is there some sort of call to "commitEditing" or "updateBinding" that I'm missing? I couldn't find any useful functions in the docs for NSCell or NSTableView.

Was it helpful?

Solution

To solve this, I implemented -tableView:setObjectValue:forTableColumn:row: in my NSArrayController subclass. I get the instance of my NSManagedObject subclass from the Row argument, and then manually assign the new model from the ObjectValue argument. I still don't know why this is necessary, when the text cells do this automatically, but it works.

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