简体   繁体   English

使用数据填充NSOutlineView-Swift

[英]Populate NSOutlineView with data - Swift

I am trying to create a sidebar in my OS X application. 我正在尝试在OS X应用程序中创建侧边栏。

I have an NSOutlineView in my xib file. 我的xib文件中有一个NSOutlineView。

I also have aa Swift file that looks like this: 我也有一个Swift文件,看起来像这样:

import Cocoa

class TKSidebarDataSource: NSObject, NSOutlineViewDataSource {

    func outlineView(outlineView: NSOutlineView,
        child index: Int,
        ofItem item: AnyObject?) -> AnyObject {
            return "Item"
    }

    func outlineView(outlineView: NSOutlineView,
        isItemExpandable item: AnyObject) -> Bool {
            return true;
    }

    func outlineView(outlineView: NSOutlineView,
        numberOfChildrenOfItem item: AnyObject?) -> Int {
            return 4
    }


}

I want to connect my swift file to my NSOutlineView in order to populate the view with my data. 我想将我的swift文件连接到NSOutlineView以便用我的数据填充视图。 How do you do this? 你怎么做到这一点? I have looked around at a lot of different places but nothing seems to be working. 我环顾了许多不同的地方,但似乎没有任何效果。


Update: 更新:

A lot of solutions suggest I ctrl-click and drag from the datasource connection of the NSOutlineView to the File's Owner placeholder. 许多解决方案建议我按住Ctrl键单击并从NSOutlineView的数据源连接拖动到文件的所有者占位符。 The only problem with that solution is that the datasource isn't the File's owner . 该解决方案的唯一问题是数据源不是文件的所有者

in -windowDidLoad (or -loadView if in a view controller), set the table's data source: 在-windowDidLoad中(如果在视图控制器中则为-loadView)中,设置表的数据源:

[outlineView setDataSource:aTKSideBarDataSource];

or 要么

outlineView.setDataSource(aTKSideBarDataSource)

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

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