2012-10-15 40 views
0

需要一些建议到:NSFetchedResultController可以做到这一点?NSFetchedResultContoller可以做到这一点吗?

UITableView: 
    [section name] <= {entity: Section, value: title} 
    [cell title] <= {entity: Cell, value: title} 

Model: 
    [entity: Section, properties: title] <->> [entity: Cell, properties: title, imgPath] 

麻烦: 计数部分,他们的标题是工作,不能从关系获取对象细胞

感谢您的帮助......

回答

1

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

// 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]; 

(我假设你有一个反比关系section细胞实体到实体)

+0

就像一个魅力:) self.fetchController.sections.count工作。 //返回计数部分 id secInfo = self.fetchController.sections [section]; [secInfo numberOfObjects]; //返回 – iTux

+0

中的行的计数id secInfo = self.fetchController.sections [section]; NSString * title = [secInfo name]; //返回标题的标题 – iTux

+0

MYMOObject * cellObj = [self.fetchController objectAtIndexPath:indexPath]; //返回单元对象 – iTux

相关问题