質問

このレイアウトでCoreDataを使用しています

enter image description here

次に、cave.titleを掲載したテーブルを、地域として並べ替えた行として見せたいと思います。次のコードでは、セクションと行が正しく表示されます。唯一の問題は、順序が正しくないということです。セクションの下の行は、そのセクションに属していません。

NSManagedObjectContext *context = country.managedObjectContext;

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    request.entity = [NSEntityDescription entityForName:@"Cave" inManagedObjectContext:context];
    request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES]];
    request.predicate = [NSPredicate predicateWithFormat:@"country = %@", country];
    request.fetchBatchSize = 20;

    NSFetchedResultsController *frc = [[NSFetchedResultsController alloc]
                                       initWithFetchRequest:request
                                       managedObjectContext:context
                                       sectionNameKeyPath:@"region.region"
                                       cacheName:nil];

    [request release];

    self.fetchedResultsController = frc;

TableViewControllerのどの部分があなたに見せるべきかわかりませんか?

enter image description here

「Bätterich」は「その他」にあるはずで、「Pertusio Acquacalda」は「Ticino」にあるはずです。コアデータのSQLファイルをチェックし、参照がすぐそこにあります。

役に立ちましたか?

解決

次の並べ替え装置を使用して問題を解決しました

NSSortDescriptor *sortDescriptorRegion = [[NSSortDescriptor alloc] initWithKey:@"region.region" ascending:YES];
NSSortDescriptor *sortDescriptorCave = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptorRegion, sortDescriptorCave, nil];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top