通过源代码搜索表示没有隐藏的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”]'。 –