uitableview 中的部分和行不匹配
我使用 coredata 与此布局
现在我想显示一个表格,其中 Cave.title 按行排序在 Region.region as 部分中。使用以下代码,它可以正确显示部分和行。唯一的问题是顺序不正确。这些部分下面的行不属于该部分。
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 Acquacalda”应在“提契诺”中 我已经检查了 Core Data 的 sql 文件,引用就在那里。
I use coredata with this layout
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?
"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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过使用以下排序描述符解决了该问题
Solved the problem by using the following sortdescriptors