如何获取所选项目outlineview Swift的父项目

问题描述

我的大纲视图中有多级层次结构。我可以使用以下代码获取所选项目及其父项目。

  func outlineViewSelectionDidChange(_ notification: Notification) {
    guard let outlineView = notification.object as? NSOutlineView else {return}

    if let item = outlineView.item(atRow: outlineView.selectedRow) as? CubeData{
      
         // Getting the parent item
          if let parentItem = outlineView.parent(forItem: item) as? CubeData{
            print("Parent Item value:",parentItem.node)
          }
        print("Selected Item value:",item.node)
       }
}

但无法获得所有的祖父项。

例如,A->B->C->D 是我的层次结构,每当我选择“D”时,我都能得到“C”和“D”。我想要所有的父项。有什么帮助吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)