Objective c NSFetchedResultsController和表视图

Objective c NSFetchedResultsController和表视图,objective-c,ios,uitableview,core-data,nsfetchedresultscontroller,Objective C,Ios,Uitableview,Core Data,Nsfetchedresultscontroller,我正在尝试将核心数据与NSFetchedResultsController一起使用 数据模型分为“树级” 父母->(许多)子女->(许多)孙辈 在表视图中,我想将父对象的所有子对象显示为部分,子对象显示为单元格。我很难想出如何解决这个问题 如有任何建议,将不胜感激 编辑 数据模型: Parent: name NSString* Id NSNumber* child NSSet* (set of childs) Child: name NSString* childId NSNumber* pa

我正在尝试将核心数据与NSFetchedResultsController一起使用

数据模型分为“树级”

父母->(许多)子女->(许多)孙辈

在表视图中,我想将父对象的所有子对象显示为部分,子对象显示为单元格。我很难想出如何解决这个问题

如有任何建议,将不胜感激

编辑 数据模型:

Parent:
name NSString*
Id NSNumber*
child NSSet* (set of childs)

Child:
name NSString*
childId NSNumber*
parent Parent*
childrensChilds NSSet* (set of childrensChilds)

ChildrensChild:
name NSString*
ChildrensChildId NSNumber*
parentChild *Child
获取请求:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Child" inManagedObjectContext:moc];
[fetchRequest setEntity:entity];

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"ChildId" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"parent.parentId = %@", self.parentId];
[fetchRequest setPredicate:predicate];

[fetchRequest setFetchBatchSize:20];

NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:moc sectionNameKeyPath:nil cacheName:@"Childrens"];
self.fetchedResultsController = theFetchedResultsController;
fetchedResultsController.delegate = self;

[fetchRequest release];
[theFetchedResultsController release];

然后,我想创建具有子名称的节标题和以childrenschild命名的单元格。

在将获取结果控制器(FRC)与表视图一起使用时,将获取实体设置为将填充行的实体。毕竟,节是可选的,但行始终是必需的

您需要做的第一件事是在数据模型中设置相互关系,如下所示:

Parent<-->>Child<-->>GrandChild
孙女是孩子,两人向下走,祖父母是父母,两人向上走。一旦您有了任何特定的
Person
对象,那么在tableview中显示就很简单了。节名将是“children”关系的排序数组,行将是每个子级自己的子级的排序数组


你根本就需要摆弄一下回执

给我们一些代码和数据模型。
Person{
  name:string
  id:number
  parent<<-->Person.children
  children<-->>Person.parent
}