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 が並べ替えられて表示されます。つまり、カテゴリを最初に選択した場合のみ、未分類の書籍名リストが表示されます。
読んでくれてありがとう、マーク