【发布时间】:2014-02-12 08:45:13
【问题描述】:
我有一个像这样的核心数据模型......
[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 值的匹配对表进行分组。
应该是……
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下(例如)。
知道如何解决这个问题吗?
【问题讨论】:
标签: ios objective-c uitableview core-data nsfetchedresultscontroller