cocoanstableviewnstablecellview

Adding a field to a NSTableCellView


I added an extra new label to a NSTableCellView in IB.

How can I wire up this new field, that I can access it like the builtin field "textfield" in tableView.make( withIdentifier ..

let cell = tableView.make(withIdentifier: "myCell", owner: self) as! NSTableCellView
cell.textField?.stringValue = data[row].firstName
cell.XXX?.stringValue = data[row].lastName

Second issue: I changed the height of the TableCellView in IB to 60 in the size inspector. The height changes in IB but not in the compiled program.


Solution

  • I solved one part of the question myself. For wiring up the new field, I created a subclass of NSTableCellView which I assigned to the TableCellView in the identity inspector.

    To this class I could crtl-drag and create an outlet which I could use like this:

    let cell = tableView.make(withIdentifier: "ItemCell", owner: self) as! ItemTableCellView
    cell.textField?.stringValue = data[row].firstName
    cell.outletForNewField.stringValue = data[row].lastName
    

    The remainig problem is the size of the tableCellView