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.

0

1 Answer 1

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.

2
  • 2
    Bingo! That worked. For some reason I don't remember binding the selection separately other times.
    – AppCrafter
    Commented Mar 26, 2014 at 6:31
  • 3
    You don't have to do this for cell based NSTableViews, only for view based NSTableViews.
    – Dirk
    Commented Mar 20, 2017 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.