How to make NSArrayController preservesSelection work for custom object?

无人久伴 提交于 2019-12-11 09:05:59

问题


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...

来源:https://stackoverflow.com/questions/46233759/how-to-make-nsarraycontroller-preservesselection-work-for-custom-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!