简体   繁体   English

创建与 NSTreeController 关联的 NSOutlineViewController

[英]creating a NSOutlineViewController associated to a NSTreeController

I try to take example on the apple sample "Navigating Hierarchical Data Using Outline and Split Views".我尝试以苹果示例“Navigating Hierarchical Data Using Outline and Split Views”为例。

I made a app with SplitViewController, I put an NSOutlineView in the left pane and in the NSOutlineViewController, I added a NSTreeController.我用 SplitViewController 制作了一个应用程序,我在左窗格中放置了一个 NSOutlineView,在 NSOutlineViewController 中,我添加了一个 NSTreeController。 Xib 在这里

I associated the datasource and the delegate of my outlineView to the OutlineViewController, and the content to the treeController我将outlineView的数据源和委托关联到OutlineViewController,并将内容关联到treeController 在此处输入图像描述

for the treeController I put the keyPth children to "children" and the object controller to a class named NodeInfo对于treeController,我将keyPth children 放到“children”中,将object controller 放到名为NodeInfo 的class 在此处输入图像描述

this class NodeInfo is filled with data from a webservice and I'm not sure, but I think it's all the difference with the Apple example which fill the treeController with the Datasource.PList.这个 class NodeInfo 充满了来自 web 服务的数据,我不确定,但我认为这与用 Datasource.PList 填充 treeController 的 Apple 示例完全不同。 In this example, the treeController (named "outlineController" have binding references as follow在此示例中,treeController(名为“outlineController”)具有如下绑定引用在此处输入图像描述

and there I don't understand how to have this binding in my own storyboard.我不明白如何在我自己的 storyboard 中进行此绑定。 can anyone provide help and explain hosto make these bindings please?任何人都可以提供帮助并解释 hosto 进行这些绑定吗?

I answer to myself To associate a NSTreeController to an OutliveView:我回答自己要将 NSTreeController 关联到 OutliveView:

A. - Bind your treeController and outlineView to the ViewController containing those. A. - 将你的 treeController 和 outlineView 绑定到包含它们的 ViewController。 In your ViewController you obtain these 2 lines:在您的 ViewController 中,您将获得以下 2 行:

B. - You need to have a class representing the differentObjest a TreeWiewController will handle. B. - 您需要有一个 class 代表 TreeWiewController 将处理的不同对象。

class NodeInfo: NSObject, Decodable {
var model: BaseModel!
@objc dynamic var title: String
@objc dynamic var children: [NodeInfo]!

override class func description() -> String {
    return "NodeInfo"
}

@objc dynamic var isLeaf: Bool {
    return children == nil || children.isEmpty
}

@objc dynamic var childCount: Int {
    return children.count
}

init(title: String, model: BaseModel) {
    self.title = title
    self.model = model
    super.init()
}

} }

Note that I need variable named BaseModel in my NodeInfo because data comes from internet and I need to populate the descendant nodes of InfoNode with their values请注意,我的 NodeInfo 中需要名为 BaseModel 的变量,因为数据来自互联网,我需要用它们的值填充 InfoNode 的后代节点

C. C。 - In the storyboard, I select the treenode, access the attributes inspector and fills the different values of treeController to make the link with NodeInfo class, as follow: - 在 storyboard 中,我 select 树节点,访问属性检查器并填充 treeController 的不同值以与 NodeInfo class 建立链接,如下所示:

在此处输入图像描述

D. - Now it's time to make the binding of all this. D. - 现在是绑定这一切的时候了。 First, in the viewController, add this variable:首先,在 viewController 中,添加这个变量:

@objc dynamic var contents: [NodeInfo] = []

Contents is the Array containing the different nodes. Contents是包含不同节点的数组。 Select the treeController and, in the binding Inspector, associates the tree with this variable: Select treeController 并在绑定检查器中将树与此变量相关联:

使用 ViewController 的变量 Contents 绑定 treeController

(Note the value for the Model Key Path) (注意 Model 密钥路径的值)

D. now select outlineView in the MainstoryBoard, access the binding inspector, and link the selectionIndexPaths to the variable contents of he ViewController: D.现在MainstoryBoard中的select outlineView,访问绑定检查器,将selectionIndexPaths链接到他ViewController的变量内容:

在此处输入图像描述

(Note the value for the Model Key Path) (注意 Model 密钥路径的值)

Bind each outlineView.tableColumns to treeController.arranged Object:将每个outlineView.tableColumns绑定到treeController.arranged Object: 在此处输入图像描述

Note the value for the Model Key Pathit's almost done for each field of the NSTableVuewCell, bond it to the correctValue in th TreeConroller.representedObject:请注意 Model 密钥路径的值几乎已为 NSTableVuewCell 的每个字段完成,将其绑定到 TreeConroller.representedObject 中的正确值:

绑定tableColumn'Cell的值。到树控制器

(Note the value for the Model Key Path) (注意 Model 密钥路径的值)

That's All就这样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM