Show list of rows in source list (NSOutlineView) in Swift

I am trying to show a simple list of strings in the sidebar of a list of sources - similar to how in Finder or in a Github application. From reading the link protocol, I don’t see which method sets what is displayed on the screen. So far I:

var items: [String] = ["Item 1", "Item 2", "Item is an item", "Thing"]
func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
    return items[index]
}

func outlineView(outlineView: NSOutlineView, isItemExpandable item: AnyObject) -> Bool {
    return false
}
func outlineView(outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int {
    if item == nil {
        return items.count
    }
    return 0
}
func outlineView(outlineView: NSOutlineView, objectValueForTableColumn tableColumn: NSTableColumn?, byItem item: AnyObject?) -> AnyObject? {
    return "ITEM"
}
func outlineView(outlineView: NSOutlineView, setObjectValue object: AnyObject?, forTableColumn tableColumn: NSTableColumn?, byItem item: AnyObject?) {
    println(object, tableColumn, item)
}
// Delegate
func outlineView(outlineView: NSOutlineView, dataCellForTableColumn tableColumn: NSTableColumn?, tem item: AnyObject) -> NSCell? {
    println("Called")
    let view = NSCell()
    view.stringValue = item as String
    return view
}

And all I get is a list of sources with four empty elements (Without text). Do I need to override another method from NSOutlineViewDelegate to display information?

0
source share
1 answer

, , outlineView:dataCellForTableColumn:item, outlineView:viewForTableColumn:item:

func outlineView(outlineView: NSOutlineView,
    viewForTableColumn tableColumn: NSTableColumn?,
    item: AnyObject) -> NSView? {

    var v = outlineView.makeViewWithIdentifier("DataCell", owner: self) as NSTableCellView
    if let tf = v.textField {
        tf.stringValue = item as String
    }
    return v
} 

, NSTableView makeViewWithIdentifier:owner:. - DataCell - identifier Interface Builder NSTableViewCell, NSOutlineView, . textField imageView; , , stringValue textField item.

+2

All Articles