How to make NSArrayController preservesSelection work for custom object?

226 views Asked by At

I have a Cocoa app with a view-based table view bound to an NSArrayController with a list of custom Employee objects.

The table view shows the list of employees. In a subview, the employee's details can be changed.

Everything is set up, so that when an employee's details are changed, the table view contents are reloaded, showing the changes. So far, so good.

Now NSArrayController has the ability to preserve the selected object across reloads via preservesSelection.

For my custom Employee objects, this does not work. I assume because the array controller can't figure out how to match the old selected employee object from the old content to the new content after the list was updated.

I overrode isEqual: in my custom Employee class, but that's never called.

The docs just say about NSArrayController.preservesSelection:

A Boolean value that indicates whether the receiver will attempt to preserve the current selection when the content changes

So how exactly does the array controller attempt to preserve the selection? It must compare the old selected object to the list of new objects somehow...

0

There are 0 answers