2

カプチーノでバインド互換のアウトラインビューデータソースを構築する最良の方法は何ですか? つまり、一種の CPTreeController

現在、ソースは JSON オブジェクト (オブジェクトと配列を含む) であり、それをアウトライン ビューに表示し、そのパラメーターを変更したり、変更の通知を受けたりしたいと考えています。(CPTreeController に読み込まれたら、シリアル化して JSON に戻す必要はありません。データソースを直接操作します)

それで:

  • どこかに隠された CPTreeController がありますか、または同様の lib を使用する準備ができていますか?
  • 独自のデータソースを書き直す場合、すべてをゼロから作成する必要がありますか、それとも CPDictionaries と CPArray を簡単に組み合わせてこのタスクを達成できますか? (バインディングに準拠する必要があることに注意してください)
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 に答える