如果同一个子对象多次存在,我如何确保 NSOutlineView.parent(forItem:) returns 是正确的父对象?

How can I ensure that NSOutlineView.parent(forItem:) returns the correct parent object if the same child object exists multiple times?

我刚刚在使用 NSOutlineView 时遇到了一个问题,不知道有没有人有解决方案。

我有一个项目层次结构,最低节点是可以出现在多个位置的对象。

例如:

现在,如果用户选择列表中的 'Toyota' 项,然后我尝试使用 outlineView.parent(forItem:) API 找到所选项目的父项将始终 return 相同的父项,大概是它遇到的第一个。

似乎在从数据源加载数据时,outlineView 并没有独立地跟踪父项。

大概解决这个问题的唯一方法是在每个节点创建某种独特的包装对象,可能是一个结构来保存公共对象。

有人知道 NSOutlineView 使用什么方法来查找给定对象的父对象吗?

来自 NSOutlineView Class 参考(强调我的):

An outline view has the following features:

  • A user can expand and collapse rows.

  • Each item in the outline view must be unique. In order for the collapsed state to remain consistent between reloads the item's pointer must remain the same and the item must maintain isEqual: sameness.