문제

I use coredata with this layout

enter image description here

Now I would like to show a table with the Cave.title as rows ordered in the Region.region as section. With the following code it shows the sections and the rows correctly. Only problem is that the order is not right. The rows below the sections don't belong to that section.

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;

I am not sure which part of the tableviewcontroller I should show to you?

enter image description here

"Bätterich" should be in "Others" and "Pertusio Acquacalda" should be in "Ticino" I have checked Core Data's sql file and the references are right in there.

도움이 되었습니까?

해결책

Solved the problem by using the following sortdescriptors

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