私はコアデータのエンティティでは、この構造を有する:ソートnsfetchedresultscontroller
ID Region SubRegion SubRegionID CellText
1 Face Mouth 2 something
2 Face Eyes 1 ...
3 Face Nose 4 ...
...
をしかし、私は私のテーブルビュー(nsfetchedresultscontroller)はこのようにソートしたい:各セクション内
:IDプロパティでソートされた細胞を セクションtableView:SubRegionの名前でソートされたSubRegionの名前です。
どうすればこの問題を解決できますか?今では私はこれをやっているが、私は知らないsubregionIDでセクションタイトルをソートするためのベストプラクティスです。お時間を
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"DataBase" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSPredicate *requestPredicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"(Region like '%@')", @"Face"]];
[fetchRequest setPredicate:requestPredicate];
NSSortDescriptor *ID = [[NSSortDescriptor alloc]
initWithKey:@"ID" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObjects: ID, nil]];
[fetchRequest setFetchBatchSize:10];
fetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:context sectionNameKeyPath:@"SubRegion"
cacheName:nil];
fetchedResultsController.delegate = self;
ありがとう!
ありがとうございます。しかし、問題はまだ私が使用したソートロジックに残っています。私はIDでソートされたセルを取得しますが、セクション名はSubRegionIDでソートされていません...私はsubregionIDでソートされた顔のサブリージョン(セクション)と、IDでソートされたセクション内のセルが必要です。アドバイスはありますか?ありがとう! – Samui
これはあなたの 'NSFetchedResultsController'を設定する方法と関係しています。 '' SubRegion ''ではなく、 '' SubRegionID ''として' sectionNameKeyPath'を設定する必要があります。あなたの 'tableView datasource'メソッド' titleForSection: 'では、IDに基づいて部分領域の名前を返します。 – Mundi
これは私が使った方法です。しかし、私はそれがsortdescriptorsを直接使用してソートできると思いました。アドバイスありがとうございます! – Samui