[英]NSFetchedResultsController: sort descriptors and sections
我有一个像这样的核心数据模型......
[Country] <--->> [League] <--->> [Match]
我正在使用NSFetchedResultsController
将Matches
显示到UITableView
。
我之前已经完成了这一百万次,但出于某种原因这些部分出错了,我无法理解为什么。
我已经创建了类似的排序描述符......
NSSortDescriptor *countrySD = [NSSortDescriptor sortDescriptorWithKey:@"league.country.name" ascending:YES];
NSSortDescriptor *leagueSD = [NSSortDescriptor sortDescriptorWithKey:@"league.name" ascending:YES];
NSSortDescriptor *dateSD = [NSSortDescriptor sortDescriptorWithKey:@"startDate" ascending:YES];
request.sortDescriptors = @[countrySD, leagueSD, dateSD];
首先,我想检查一下我是否按正确的顺序排列。 这应首先按country.name
排序,然后按league.name
排序,然后按startDate
排序。
即
Albania
任何事情都应该先于Spain
。 League 1
任何东西都应该出现在League 2
。 startDate
顺序显示。 然后我用这个创建NSFRC
......
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.moc sectionNameKeyPath:@"league.leagueID" cacheName:nil];
所以这应该通过匹配不同的league.leagueID
值对表进行league.leagueID
。
它应该像......
Albania - League 1
12:00
13:00
Albania - League 2
09:00
14:00
France - League 1
09:00
Spain - A League
08:00
12:00
Spain - B League
09:00
虽然不行。 我为同一个联盟获得了多个标题。 一些匹配出现在错误的标题下...
我已经检查了错误联赛中出现的比赛的值(NSLogged),他们实际上有正确的联赛。 因此即使他们拥有Spain - A League
他们也会出现在France - League A
(例如)之下。
知道如何解决这个问题吗?
用作sectionNameKeyPath
参数的键路径必须与第一个排序描述符中使用的键相同(或生成相同的相对排序)。
(据我所知)没有办法使用两个或多个排序描述符将获取结果控制器的结果分组到各个部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.