iPhone:无法对多个关系进行NSSortDescriptor描述。如何分类?

iPhone:无法对多个关系进行NSSortDescriptor描述。如何分类?,iphone,core-data,entity-relationship,nsfetchrequest,nssortdescriptor,Iphone,Core Data,Entity Relationship,Nsfetchrequest,Nssortdescriptor,我正在使用NSFETCH请求,我正在通过NSSortDescriptor对其进行排序 这非常适用于正在获取的实体的所有属性 在那个实体中只有一个问题(不是一直存在吗?),我和另一个实体有关系,我也想对这个问题进行排序。但它给了我以下错误: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'to-many key not allowed here' 以下是我的核心数据设置:

我正在使用NSFETCH请求,我正在通过NSSortDescriptor对其进行排序

这非常适用于正在获取的实体的所有属性

在那个实体中只有一个问题(不是一直存在吗?),我和另一个实体有关系,我也想对这个问题进行排序。但它给了我以下错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'to-many key not allowed here'
以下是我的核心数据设置:

这是我的密码:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entityMonth = [NSEntityDescription entityForName:@"Month" inManagedObjectContext:_managedObjectContext];
    [fetchRequest setEntity:entityMonth];

    NSSortDescriptor *sortDescriptorItem = [NSSortDescriptor sortDescriptorWithKey:@"item.nr" ascending:YES]; //THIS ONE CAUSES THE ERROR!
    NSSortDescriptor *sortDescriptorMonth = [[NSSortDescriptor alloc]initWithKey:@"month" ascending:YES];
    NSSortDescriptor *sortDescriptorYear = [[NSSortDescriptor alloc]initWithKey:@"year" ascending:YES];


    NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptorYear, sortDescriptorMonth, sortDescriptorItem, nil];
    [fetchRequest setSortDescriptors:sortDescriptors];

    NSError *error = nil;
    self.stages = [_managedObjectContext executeFetchRequest:fetchRequest error:&error];

您无法对
item.nr
进行排序,因为
Month
对象与许多
item
对象相关,因此,每个
对象都有多个
item.nr
值。

那么,如果我想根据nr属性对所有项目进行排序,我应该如何处理这些值呢?@iJar:fetch请求返回
对象,而不是
项目
对象,因此,我还不明白您到底想要什么。此数据显示在表视图中。month.name显示为节标题,项目为每个节下的行。month.year和month.month对节进行排序。现在,我正在寻找一种基于item.id对行进行排序的方法。希望这能澄清我的意图。@iJar:你使用获取结果控制器吗?不,我现在不使用。这有帮助吗?