creating a NSOutlineViewController associated to a NSTreeController

130 Views Asked by At

I try to take example on the apple sample "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. the Xib is here

I associated the datasource and the delegate of my outlineView to the OutlineViewController, and the content to the treeController enter image description here

for the treeController I put the keyPth children to "children" and the object controller to a class named NodeInfo enter image description here

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. In this example, the treeController (named "outlineController" have binding references as follow enter image description here

and there I don't understand how to have this binding in my own storyboard. can anyone provide help and explain hosto make these bindings please?

1

There are 1 best solutions below

2
Patrice Rapaport On

I answer to myself To associate a NSTreeController to an OutliveView:

A. - Bind your treeController and outlineView to the ViewController containing those. In your ViewController you obtain these 2 lines:

B. - You need to have a class representing the differentObjest a TreeWiewController will handle.

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

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:

enter image description here

D. - Now it's time to make the binding of all this. First, in the viewController, add this variable:

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

Contents is the Array containing the different nodes. Select the treeController and, in the binding Inspector, associates the tree with this variable:

Binding treeController wih the variable Contents of ViewController

(Note the value for the Model Key Path)

D. now select outlineView in the MainstoryBoard, access the binding inspector, and link the selectionIndexPaths to the variable contents of he ViewController:

enter image description here

(Note the value for the Model Key Path)

Bind each outlineView.tableColumns to treeController.arranged Object: enter image description here

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:

Bind the value of tableColumn'Cell. to treeController

(Note the value for the Model Key Path)

That's All