Anokrize Anokrize - 10 months ago 216
Swift Question

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


The standard NSTableCellView with text and image has an outlet imageView

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