Tom el Safadi
Tom el Safadi

Reputation: 6746

OSX Swift add image into nstableview

I have added a tableview and as well configured the cell with an identifier. Everything works fine, the text of the cell gets displayed. I have just one problem and don't know how to solve it. How can I change the image of the tableview cell?

Here is my code:

func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? {
    let cellView = tableView.makeViewWithIdentifier("cell", owner: self) as! NSTableCellView

    cellView.textField!.stringValue = self.objects.objectAtIndex(row) as! String

    return cellView
}

How can I change the image which is also present inside the cell?

enter image description here

Upvotes: 1

Views: 1778

Answers (1)

vadian
vadian

Reputation: 285059

The standard NSTableCellView with text and image has an outlet imageView

cellView.imageView!.image = NSImage(named:"MyImage")

Upvotes: 3

Related Questions