[英]creating a NSOutlineViewController associated to a NSTreeController
我嘗試以蘋果示例“Navigating Hierarchical Data Using Outline and Split Views”為例。
我用 SplitViewController 制作了一個應用程序,我在左窗格中放置了一個 NSOutlineView,在 NSOutlineViewController 中,我添加了一個 NSTreeController。
我將outlineView的數據源和委托關聯到OutlineViewController,並將內容關聯到treeController
對於treeController,我將keyPth children 放到“children”中,將object controller 放到名為NodeInfo 的class
這個 class NodeInfo 充滿了來自 web 服務的數據,我不確定,但我認為這與用 Datasource.PList 填充 treeController 的 Apple 示例完全不同。 在此示例中,treeController(名為“outlineController”)具有如下綁定引用
我不明白如何在我自己的 storyboard 中進行此綁定。 任何人都可以提供幫助並解釋 hosto 進行這些綁定嗎?
我回答自己要將 NSTreeController 關聯到 OutliveView:
A. - 將你的 treeController 和 outlineView 綁定到包含它們的 ViewController。 在您的 ViewController 中,您將獲得以下 2 行:
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()
}
}
請注意,我的 NodeInfo 中需要名為 BaseModel 的變量,因為數據來自互聯網,我需要用它們的值填充 InfoNode 的后代節點
C。 - 在 storyboard 中,我 select 樹節點,訪問屬性檢查器並填充 treeController 的不同值以與 NodeInfo class 建立鏈接,如下所示:
D. - 現在是綁定這一切的時候了。 首先,在 viewController 中,添加這個變量:
@objc dynamic var contents: [NodeInfo] = []
Contents是包含不同節點的數組。 Select treeController 並在綁定檢查器中將樹與此變量相關聯:
(注意 Model 密鑰路徑的值)
D.現在MainstoryBoard中的select outlineView,訪問綁定檢查器,將selectionIndexPaths鏈接到他ViewController的變量內容:
(注意 Model 密鑰路徑的值)
將每個outlineView.tableColumns綁定到treeController.arranged Object:
請注意 Model 密鑰路徑的值幾乎已為 NSTableVuewCell 的每個字段完成,將其綁定到 TreeConroller.representedObject 中的正確值:
(注意 Model 密鑰路徑的值)
就這樣
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.