trentjones21
trentjones21

Reputation: 571

Populate NSOutlineView with data - Swift

I am trying to create a sidebar in my OS X application.

I have an NSOutlineView in my xib file.

I also have a a Swift file that looks like this:

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. 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. The only problem with that solution is that the datasource isn't the File's owner.

Upvotes: 1

Views: 512

Answers (1)

Rupert Pupkin
Rupert Pupkin

Reputation: 790

in -windowDidLoad (or -loadView if in a view controller), set the table's data source:

[outlineView setDataSource:aTKSideBarDataSource];

or

outlineView.setDataSource(aTKSideBarDataSource)

Upvotes: 1

Related Questions