NSTextField in NSTableView doesn't update its value

321 views Asked by At

I have a table, when I create some rows with changed text it's doesn't show in the App.

var items : [String] = []

override func viewDidLoad() {

    super.viewDidLoad()
    items.append("Apples")
    items.append("Oranges")

    tableView.reloadData()

}

func numberOfRows(in tableView: NSTableView) -> Int {

    return items.count

}

func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any?{

    let result : NSTableCellView = tableView.make(withIdentifier: tableColumn!.identifier, owner: self) as! NSTableCellView

    print(tableColumn?.title)
    result.textField?.stringValue = items[row]
    print(result.textField?.cell?.title)

    return result

}

}

In console it looks ok, but it shows previous values

enter image description here

enter image description here

By default the Log column's textfield = 1 and date = 2

1

There are 1 answers

0
osadchi On

I got it. I've changed the type to cell-based and the tableView funtion.

func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {

    return items[row]

}