0

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;
}
Gary Simpson
  • 2,677
  • 2
  • 17
  • 18

1 Answers1

1

Try:

var cell = tableView.makeViewWithIdentifier("MainCell", owner: self) as SubclassOfNSTableCellView
vacawama
  • 150,663
  • 30
  • 266
  • 294
  • I could kiss you :-) Thank's i do not think i'd have thought about that at this early stage of my cocoa development. Works a treat and makes the extra text field available by reference cell.tableCellDateField. – Gary Simpson Nov 22 '14 at 10:47
  • I'm glad I could help. You have enough rep now, you could also up vote the answer. :-) – vacawama Nov 22 '14 at 10:49