Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSArrayController selection not updating with NSTableView binding

This has been befuddling me for hours...

I have an object (CuesDoc) with a property (NSMutableArray *cuesArray) and some other properties. The cues array holds multiple Cue objects. There is a property called (CuesDoc*) currentCuesDoc in my AppDelegate.

In IB, I have an NSArrayController, which is bound to the AppDelegate.currentCuesDoc.cuesArray.

I have a view-based NSTableView which is bound to the NSArrayController and can add/remove/edit values in the table and cuesArray. So far so good.

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

When the view first appears, the detail fields populate with the contents of the first item in the table view, however when I select other rows, the detail fields do not update to reflect the current selection.

I added an observer to selectionIndexes and selection for the NSArrayController, and when the view appears, I get called for the observeValueForKeyPath: method once, but not after changing selections.

like image 748
AppCrafter Avatar asked Mar 26 '14 01:03

AppCrafter


1 Answers

For view-based NSTableViews, you must bind the tableView's selection indexes to the array controller key of selectionIndexes to keep the view's selection in sync with the controller's selection. Selection bindings are separate from content bindings. The older, cell-based NSTableView APIs did not require this step.

like image 135
stevesliva Avatar answered Jan 03 '23 19:01

stevesliva