문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top