我有一個大綱視圖委託,我重寫outlineView:dataCellForTableColumn:項目:使我的大綱視圖中的單元格按鈕(見this question)。這裏是我的代表的代碼形式:outlineView:dataCellForTableColumn:item:有奇怪的副作用
- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item;
{
MyCell * myCell = [[MyCell alloc] init];
// return nil;
return myCell;
}
這樣做有一個奇怪的副作用。在我的大綱視圖的數據源中,方法outlineView:objectValueForTableColumn:byItem:始終爲tableColumn獲取一個空值。
的代碼是:
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
printf("tableColumn:%s\ttable identifier: %s\n", [[tableColumn className] cString], [[tableColumn identifier] cString]);
return [item valueForKey:[tableColumn identifier]];
}
,輸出是:
tableColumn:(null) table identifier: (null)
什麼奇怪的是,當我實現outlineView這只是發生:dataCellForTableColumn:項目:方法。我在這裏錯過了什麼?
編輯:
修改這樣的委託功能似乎來解決這個問題:
- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item;
{
printf("delegate column identifier: %s\n", [[tableColumn identifier] cStringUsingEncoding:NSASCIIStringEncoding]);
if (tableColumn == nil)
{
return nil;
}
MyCell * aCustomCell = [[MyCell alloc] init];
return aCustomCell;
}
不過,我真的不明白是怎麼回事。如果任何人都可以解釋,那會很有幫助。謝謝!