2011-11-30 49 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」]'。 –