2

在卡布奇诺中构建绑定兼容的大纲视图数据源的最佳方法是什么?即一种CPTreeController

我的源当前是一个 jSON 对象(包含对象和数组),我想将它显示到大纲视图中,并且能够更改其参数/获得更改通知。(一旦加载到 CPTreeController 中,我不需要将其序列化回 JSON,我将直接使用数据源)

然后:

  • 某处是否有隐藏的 CPTreeController 或类似的库可供使用?
  • 如果我重写自己的数据源,我应该从头开始编写,还是可以轻松混合 CPDictionaries 和 CPArrays 来完成这项任务?(请记住,它应该符合绑定)
4

1 回答 1

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"];
}
于 2011-11-30T10:05:02.670 回答