0

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?

  • The Content outlet of the outlineController should not be connected to the outline view. Is the image of the sample code or yours? Which binding do you need help with? If you think you have everything connected and bound and it doesn't work then post the error symptoms please. – Willeke Nov 25 '21 at 07:35
  • The image is from apple sample code. in the referencing Binding, arrangedObjects is connected with the outlineView, and this is the binding I don't know how to realize – Patrice Rapaport Nov 25 '21 at 09:45
  • The Referencing Bindings are from the outline view to the tree controller. Select the outline view, go to the Bindings Inspector and take a look. – Willeke Nov 25 '21 at 11:14
  • yes that's why I have trouble: when I make this binding, it juste offers only datasource, delegate and some actions. – Patrice Rapaport Nov 25 '21 at 13:47

1 Answers1

-1

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

  • Do all cells display the value of the selected row? C. select the tree controller, not the tree node. Don't bind the table columns, this binding is used by the cell based outline view. Bind the text field to the cell view, model keypath `objectValue.title`. See [Populating a Table View Using Cocoa Bindings](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/TableView/PopulatingViewTablesWithBindings/PopulatingView-TablesWithBindings.html#//apple_ref/doc/uid/10000026i-CH13-SW1). – Willeke Nov 26 '21 at 12:24
  • Yes, you are right. in C, it was a written mistake, I had the tree controller selected – Patrice Rapaport Nov 27 '21 at 04:59