简体   繁体   中英

Get a reference to an extra text field in an NSTableCell

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;
}

尝试:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM