Uitableview NSFetchedResultContoller可以做到吗?

Uitableview NSFetchedResultContoller可以做到吗?,uitableview,core-data,nsfetchedresultscontroller,Uitableview,Core Data,Nsfetchedresultscontroller,需要一些建议:NSFetchedResultController可以这样做吗 UITableView: [节名]这应该是可能的。事实上,我认为如果创建FRC时将sectionNameKeyPath设置为“section.title”,则可以使用“标准”表视图数据源方法和获取结果控制器委托方法: (我假设单元格实体与节实体之间存在反向关系section)像符咒一样工作:)self.fetchController.sections.count;//节id secInfo的返回计数=self.fetc

需要一些建议:NSFetchedResultController可以这样做吗

UITableView:

[节名]这应该是可能的。事实上,我认为如果创建FRC时将
sectionNameKeyPath
设置为“section.title”,则可以使用“标准”表视图数据源方法和获取结果控制器委托方法:


(我假设单元格实体与节实体之间存在反向关系
section

像符咒一样工作:)self.fetchController.sections.count;//节id secInfo的返回计数=self.fetchController.sections[section];[secInfo numberOfObjects];//返回sectionid secInfo=self.fetchController.sections[section]中的行计数;NSString*title=[secInfo name];//返回HeaderMyObject*cellObj=[self.fetchController objectAtIndexPath:indexPath]的标题;//返回单元格对象
UITableView:
  [section name] <= {entity: Section, value: title}
    [cell title] <= {entity: Cell, value: title}

Model:
  [entity: Section, properties: title] <->> [entity: Cell, properties: title, imgPath]
// Fetch "Cell" entities:
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Cell"];

// First sort descriptor for grouping the cells into sections, sorted by section title:
NSSortDescriptor *sort1 = [NSSortDescriptor sortDescriptorWithKey:@"section.title" ascending:YES];
// Second sort descriptor for sorting the cells within each section:
NSSortDescriptor *sort2 = [NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObjects:sort1, sort2, nil];

NSFetchedResultsController *frc = [[NSFetchedResultsController alloc]
                                        initWithFetchRequest:request
                                        managedObjectContext:context
                                          sectionNameKeyPath:@"section.title"
                                                   cacheName:nil];