2014-11-22 28 views
0

我製作了NSTableCell的一個子類,並將其作爲表的數據源和委託。獲取對NSTableCell中額外文本字段的引用

該表是基於視圖的。

單元格是一個圖像和文本單元格,我添加了一個額外的文本字段。

我有一個子類額外字段的引用出口。

我已經將額外的字段引用出口從IB中的表格視圖單元連接到額外的字段。

表中的一切仍然像以前一樣工作,我將細胞視圖子類化,並將所有數據源和精密代碼移到那裏。

但是..我仍然不能在子類中引用新的額外字段,如我所期望的那樣。

請看下面我期望能夠做到的。但tableCellDate(單元格中的新字段)未被識別爲可用引用。

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

嘗試:

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

我可以吻你:-)謝謝的,我不認爲我會在我的可可發展的早期階段曾想過這一點。通過引用cell.tableCellDateField工作處理並使額外的文本字段可用。 – 2014-11-22 10:47:15

+0

我很高興能幫上忙。你現在有足夠的代表,你也可以投票回答。 :-) – vacawama 2014-11-22 10:49:50