Get a reference to an extra text field in an NSTableCell

195 views Asked by At

I made a subclass of NSTableCell and made it the data source and delegate of the table.

The table is view based.

The cell was an image and text cell that i added an extra text field into.

I have a referencing outlet for the extra field in the subclass.

I have connected the extra field referencing outlet from the table view cell in IB to the extra field.

Everything in the table still works as before i subclassed the cell view and moved all the data source and delicate code over there.

But.. I still can not reference the new extra field in the delicate method within the subclass as I expected to be able to.

See below what i expected to be able to do now. But the tableCellDate (the new field in the cell) is not recognised as an available reference.?

class SubclassOfNSTableCellView: NSTableCellView, NSTableViewDelegate{

@IBOutlet weak var tableCellDateField: NSTextField!

// other ib outlets are here



func tableView(tableView: NSTableView!,viewForTableColumn tableColumn: NSTableColumn!, row: Int) -> NSView! {
    var cell = tableView.makeViewWithIdentifier("MainCell", owner: self) as NSTableCellView
    var theDisplayName: String = recordingsDictionaryArray[row]["name"] as String
    cell.textField?.stringValue = theDisplayName

    // what i expected to be able to do below was
    // cell.tableCellDateField.stringValue = recordingsDictionaryArray[row]["date"] as String

    return cell;
}
1

There are 1 answers

2
vacawama On BEST ANSWER

Try:

var cell = tableView.makeViewWithIdentifier("MainCell", owner: self) as SubclassOfNSTableCellView