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.
I associated the datasource and the delegate of my outlineView to the OutlineViewController, and the content to the treeController
for the treeController I put the keyPth children to "children" and the object controller to a class named NodeInfo
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
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?
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:
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:
(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:
(Note the value for the Model Key Path)
Bind each outlineView.tableColumns to 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:
(Note the value for the Model Key Path)
That's All
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.