通過源代碼搜索表示沒有隱藏的CPTreeController,因此您可以編寫自己的CPTreeController實現並將其提供給社區,也可以實現數據源協議具體型號,這樣的事情:
- (int)outlineView:(CPOutlineView)theOutlineView numberOfChildrenOfItem:(id)theItem
{
if (theItem == nil)
theItem = rootNode;
return [[theItem childNodes] count];
}
- (id)outlineView:(CPOutlineView)theOutlineView child:(int)theIndex ofItem:(id)theItem
{
if (theItem == nil)
theItem = rootNode;
return [[theItem childNodes] objectAtIndex:theIndex];
}
- (BOOL)outlineView:(CPOutlineView)theOutlineView isItemExpandable:(id)theItem
{
if (theItem == nil)
theItem = rootNode;
return [[theItem childNodes] count] > 0;
}
- (id)outlineView:(CPOutlineView)anOutlineView objectValueForTableColumn:(CPTableColumn)theColumn byItem:(id)theItem
{
return [[theItem representedObject] valueForKey:"name"];
}
不知就不會有事做了[CPTree(http://cappuccino.org/learn/documentation/interface_c_p_tree_node.html)了。那麼哪個對象將負責鍵綁定?我的數據源或我將添加的對象? –
'CPTreeNode'幫助很大,因爲您不必重新實現樹數據結構。在上面的'rootNode'和'theItem'上面的例子是'CPTreeNode's。由於沒有顯式綁定,取決於你哪個對象將負責鍵綁定,但對我來說,'CPTreeNode'似乎也將樹結構與實際數據分開,所以最好綁定到添加的對象,如'[[ [theItemrepresentObject] valueForKey:「name」]'。 –