0

IB バインディングを使用して NSTableColumn 内のバインドされたデータをソートします。

キー: NSTableColumn 、並べ替え、NSArrayController、コンテンツ セット

contentSet は、TableColumn のデータ ソースのように機能します

これは、2 つの単一列 NSTableViews を持つ SplitView を処理します。TableViews の名前は、BookCategory と Books です。Books テーブルには、book_titles を含む 1 つの列があります。クラス BookCategory は、Book と 1 対多の関係にあります。

BookCategory テーブルは、ロード時に以下を使用してソートされます。

@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

これにより、列ヘッダーをクリックするとソートが有効になるように見えます。

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

問題を言い換えると、本のタイトルを含むテーブルビューはソートされずに読み込まれます。ユーザーが列ヘッダーを最初にクリックした後にのみソートされます。

アート、歴史、スポーツの 3 つの本のカテゴリがあるとします。アプリが分割ビューの左側のテーブルを読み込むと、次のように並べ替えられます。

Art
History
Sports

ユーザーが ANY カテゴリを選択すると、カテゴリ内のすべての書籍のタイトルが右側の tableView に表示されますが、並べ替えられません。ユーザーが book_title TableColumn のヘッダーをクリックすると、最初の並べ替えが列で行われます。その後、ANY ブック カテゴリを選択すると、右側の tableView に book_titles が並べ替えられて表示されます。つまり、カテゴリを最初に選択した場合のみ、未分類の書籍名リストが表示されます。

読んでくれてありがとう、マーク

4

1 に答える 1

0

これは、最終的に私にとって何がうまくいったかの概要です。

            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         
于 2011-05-23T23:57:18.940 に答える