sections and rows don't match in uitableview
I use coredata with this layout
Now I开发者_StackOverflow 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?
"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];
精彩评论