2011-11-30 51 views
2

什么是建立一个卡布奇诺结合兼容的大纲视图datasouce最好的方法是什么?即一种CPTreeControllerCPTreeController(卡布奇诺)

我的源当前是一个jSON对象(包含对象和数组),我想将其显示为大纲视图以及能够更改其参数/获取更改通知。 (一旦装入CPTreeController,我不需要序列化回JSON,我会与数据源直接合作)

然后:

  • 是否有一个隐藏的CPTreeController某处或类似的LIB准备使用 ?
  • 如果我重写我自己的数据源,我应该从头开始编写它,还是可以轻松地混合使用CPDictionaries和CPArrays来实现此任务? (请记住它应该符合绑定)

回答

1

通过源代码搜索表示没有隐藏的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"]; 
} 
+0

不知就不会有事做了[CPTree(http://cappuccino.org/learn/documentation/interface_c_p_tree_node.html)了。那么哪个对象将负责键绑定?我的数据源或我将添加的对象? –

+1

'CPTreeNode'帮助很大,因为您不必重新实现树数据结构。在上面的'rootNode'和'theItem'上面的例子是'CPTreeNode's。由于没有显式绑定,取决于你哪个对象将负责键绑定,但对我来说,'CPTreeNode'似乎也将树结构与实际数据分开,所以最好绑定到添加的对象,如'[[ [theItemrepresentObject] valueForKey:“name”]'。 –