Question

Tri des données liées dans NSTableColumn en utilisant la liaison IB.

Clés: nstableColumn, tri, nsArrayController, ensemble de contenu

Un contenu sert comme une source de données pour une table

Cela traite d'un SplitView avec deux colonnes uniques nstableViews Les noms des tableaux de table sont BookCategory et Books. La table des livres a une seule colonne avec book_titles. La catégorie de la classe a une relation à de nombreuses relations à réserver.

La table de bookcategory est triée à chargement en utilisant:

@implementation MyBookCategoryController

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
       NSSortDescriptor *descript = 
       [NSSortDescriptor sortDescriptorWithKey:@"name"
                    ascending:YES selector:@selector(caseInsensitiveCompare:)];

       [self setSortDescriptors:[[NSArray arrayWithObject:descript] autorelease] ];

    }
    return self;
}

This same approach fails to sort the BookTitle table at load.  !!

The BookTitle table/column loads unsorted.

For the TableColumn the Attributes Inspector has  
 Sort Key:title
 Selector: caseInsensitiveCompare:
 Order: Ascending

Cela semble activer le tri lorsque l'on clique sur l'en-tête de la colonne.

I want the data sorted when the view loads. 

The binding inspector for this book_title column has:
 Value : BookCategoryArrayController.arrangedObjects.name

The BookTitleArrayController in binding inspector shows 
 Content Set: Book Category ArrayController.selection.books

Pour reformuler le problème, le TableView avec les titres du livre chargera non. Il ne trie qu'après le premier clic de l'utilisateur sur l'en-tête de la colonne.

Disons qu'il y a trois catégories de livres Art, Histoire, Sports. Lorsque l'application charge la table gauche dans le SplitView est triée, c'est-à-dire:

Art
History
Sports

Lorsque l'utilisateur sélectionne n'importe quelle catégorie, les titres de tous les livres de la catégorie apparaissent dans la bonne table de table mais non triés. Si l'utilisateur clique sur l'en-tête de la tablecolumn book_title, le tri initial est effectué sur la colonne. Par la suite, la sélection de n'importe quelle catégorie de livre provoque un affichage trié de book_titles dans la bonne table. Autrement dit, seule la première sélection d'une catégorie se traduit par une liste de titre de livre non triée.

Merci beaucoup d'avoir lu, Mark

Était-ce utile?

La solution

C'est un aperçu de ce qui a finalement fonctionné pour moi.

            Sorting with CategoryArrayController (NSArrayController)

      Bindings Inspector
         Content Set  Bind to: CategoryArrayController.selection.books

         SortDescriptors Bind to: ShareUserDefaultsController
          Controller Key: values
          sortDescriptors  (note:  exclamation point)
          NSUnarchiveFromData

    Shared User Defaults Controller 
        Referencing Outlets
          userDefaultsController -- AppController (C:AppController)
        Referencing Bindings
            values.sortDescriptors -- Sort Descriptors Rx Array Controller (C:NSArrayController)
                                   -- Sort Descriptors Category Array Controller (C:NSArrayController)  

      Clicking on Category Header does no sort. Selects all in Cats, and empties Recipe Table
      Comments on the above welcome.

    TableViewCat (NSTableController)
        Attributes Inspector
          TableView
            Selection 
                Empty,Column,Type Select
          Control
             State.Enabled
        Connections Inspec
            None
        Bindings Inspec
            None

      TableColumn -Category (NSTableColumn)
        Attributes Inspec
            Sort Key : None
        Bindings Inspec
            Value -- Category Array Controller.arrangedObjects.name


    Sorting with RxArrayController (C:NSArrayController)
      Attributes Inspec
         Array Controller: 1-5 of 6
         Object Controller
           EntityName: Recipe
             Prepares Content
             Editable
      Connections Inspector
        Referencing Bindings
          arrangedObjects.name -- Value - Table Column Recipe
          selectedObjects      -- Double Click Argument - Table View Book
      Bindings Inspector
       Controller Content
         Content Set
           Category Array Controller.selection.books
       Controller Content Parameters    
         Sort Descriptors Bind to: ShareUserDefaultsController
          Controller Key: values
          sortDescriptors  (note:  exclamation point)
          NSUnarchiveFromData
        Parameters  
          Managed Object Context(App Delegate.manangedObjectContext

    TableView Book (NSTableView)
        Attributes Inspector
          TableView
            Selection Empty,Column,Type Select
          Control
            State.Enabled
        Connections Inspec
            Bindings
                DoubleClick Argument -- Book Array Controller.selectedObjects
                Double Click Target  -- App Delegate.self
        Bindings Inspec
            Double Click Argument (Book Array Controller.selectedObjects)
            Double Click Target (App Delegate.self)
                Bind To: App Delegate
                    Model Key Path: self  (Repeats ?)
                    Selector Name: newBookAction: 
                      Conditionally Sets Enabled

      TableColumn - Book (NSTableColumn)
        Attributes Inspec
            Sort Key : None
        Connections Inspec
            Bindings
                Value -- Book Array Controller.arrangedObjects.name
        Bindings Inspec
            Value -- Book Array Controller.arrangedObjects.name         
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top