NSArrayController selection not updated with NSTableView binding

It bothered me for hours ...

I have an object (CuesDoc) with a property (NSMutableArray *cuesArray)and some other properties. An array cuescontains several objects Cue. In mine AppDelegatethere is a property called (CuesDoc*) currentCuesDoc.

In IB, I have NSArrayControllerone associated with AppDelegate.currentCuesDoc.cuesArray.

I have NSTableViewone that is attached to NSArrayControllerand can add / remove / edit values ​​in a table and cuesArray. So far so good.

I have detailed fields below the ones that are bound to NSArrayController.selection, with the model key path set for each property.

When a view first appears, the part fields are filled with the contents of the first element in the table view, however, when I select other rows, the part fields are not updated to reflect the current selection.

I added an observer to selectionIndexesand selectionfor NSArrayController, and when the view appears, I get a method call observeValueForKeyPath:once, but not after changing the selection.

+4
source share
1 answer

You must bind tableView selection indices to the array controller key in selectionIndexesorder to keep the view selection in sync with the controller selection. Selection associations are independent of content bindings.

+15
source

Source: https://habr.com/ru/post/1533446/


All Articles