Cocoa Bindings for hierarchical model

后端 未结 2 888
谎友^
谎友^ 2021-01-15 04:15

I have a NSCollectionView based master-detail interface, where I want to display Boards in the master and Lists+Cards in the detail view.

Board, holds a

相关标签:
2条回答
  • 2021-01-15 04:29

    If I understand properly, in the master interface, the user selects a Board. Then, the detail interface should show the selected Board's lists. If so, the ListArrayController should be bound to BoardArrayController, controller key selection (not arrangedObjects), model key path lists.

    Similarly, the CardArrayController should be bound to ListArrayController, controller key selection, model key path cards. Although it's not clear to me if the user has to first select a List and then sees a pop-up with that List's cards or if the pop-up is present in each item in the second collection view. If that's the case, then you'll need a separate array controller for each item, which is easiest if the item view is in a separate NIB.

    0 讨论(0)
  • 2021-01-15 04:30

    If each list is the representedObject for each view item in the collection view, then you can populate each popupButton with a readonly NSArray property dependent upon the cards array that is in each list. In the List class add arrangedCards as a property.

    - (NSArray *)arrangedCards
    {
        return [[self valueForKey:@"cards"] sortedArrayUsingDescriptors:
          [self arrangedCardsSortDescriptors]];
    } 
    

    Use the sort you want for the popup. This arranges by name.

    - (NSArray *)arrangedCardsSortDescriptors
    {
        NSSortDescriptor *sortByName = [[NSSortDescriptor alloc] initWithKey:
          @"name" ascending:YES];
        return @[sortByName];
    }
    

    Bind the Content of the popup to the NSCollectionViewItem.

    Model Key Path is representedObject.arrangedCards.

    Use representedObject.arrangedCards.name as the Content Values.

    0 讨论(0)
提交回复
热议问题