NSArrayController selection not updating with NSTableView binding
Asked Answered
D

1

9

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.

Doolie answered 26/3, 2014 at 1:41 Comment(0)
T
21

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.

Thrips answered 26/3, 2014 at 2:44 Comment(2)
Bingo! That worked. For some reason I don't remember binding the selection separately other times.Doolie
You don't have to do this for cell based NSTableViews, only for view based NSTableViews.Audette

© 2022 - 2024 — McMap. All rights reserved.