【问题标题】:Expand item in NSOutlineView with NSTreeController使用 NSTreeController 展开 NSOutlineView 中的项目
【发布时间】:2021-09-24 19:28:43
【问题描述】:

我正在尝试(未成功)从单击的披露按钮中获取节点

我觉得这个功能比较合适:

func outlineViewItemDidExpand(_ notification: Notification) {
     
     let nodeToExpand = notification.userInfo as! Node
     let nodeToExpand2 = notification.userInfo["NSObject"] as! Node

    //Error @selector(_outlineControlClicked:) from sender NSButton 0x10053d710

}

【问题讨论】:

  • 是从代码中展开节点还是想在用户展开节点时得到通知?
  • 我需要获取分配给该节点的 URL (Node.url) 以便将 childrenNode 附加到他的 parentNode。
  • 是什么阻止您从 nodeToExpand2 获取 URL?
  • 这是我尝试使用上层代码时的错误消息:-->“无法将 'NSKVONotifying_NSTreeControllerTreeNode' (0x600003018b40) 类型的值转换为 'Editor.Node' (0x100040720)。执行 @selector(_outlineControlClicked) :) 来自发件人 NSButton 0x100649c90"

标签: swift objective-c nsoutlineview nstreecontroller


【解决方案1】:

NSTreeController 将您的节点包装在 NSTreeNode 对象中。您的节点是representedObject 中的NSTreeNode

if let treeNode = notification.userInfo["NSObject"] as? NSTreeNode,
   let node = treeNode.representedObject as? Node {
    …
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 2019-04-20
    • 1970-01-01
    相关资源
    最近更新 更多