lundi 25 septembre 2017

How to maintain TableView selection with "Handles Content As Compound Value"

I have an issue maintaining the selection on an NSTableView. I am using xCode 8.3.3 with Swift 3.1 and building for macOS.

The cell-based tableView is created in IB and has an NSButtonCell (a checkbox) in the first column of the table. This column is bound to ModifiersController.arrangedObjects.enabled. The checkbox functions as expected meaning it can properly be checked and unchecked.

The problem is that when I change the state of the checkbox by clicking on it, the selected row becomes unselected and the first row becomes selected. No matter which row is selected when I change the checkbox, it is always the first row that becomes selected.

What I expect to happen is that checking/unchecking the box should not affect the selected rows (highlighting).

enter image description here

The ArrayController is named 'ModifiersController', and its Content Array is bound to a User Defaults Controller key named MinimizeModifiers. The MinimizeModifiers is a dictionary of values with a custom Value Transformer. Because of this I have enabled the checkbox for Handles Content As Compound Value

arraycontroller_bindings

When Handles Content As Compound Value is off (disabled), the selection in the table is properly maintained, but the underlying code (bindings to UserDefaults) does not work.

When Handles Content As Compound Value is on, the UI element values are properly bound to UserDefaults, however, this is what appears to cause the table to lose the current selection.

So, the question is: How can I maintain table row selection when Handles Content As Compound Value is enabled?




Aucun commentaire:

Enregistrer un commentaire