部分和行不匹配在UITATION VIEW中
-
25-10-2019 - |
题
我在这个布局中使用Coredata
现在,我想显示带有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的哪一部分?
“bätterich”应该在“其他”和“ pertusio aquacalda”中,应该在“ ticino”中,我已经检查了核心数据的SQL文件,并且参考文献在其中。
解决方案
通过使用以下sortDeScriptor解决了问题
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];
不隶属于 StackOverflow