0

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

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

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

麻烦: 部分的计数,它们的标题正在工作,无法从与 Cell 的关系中获取对象

感谢帮助...

4

1 回答 1

1

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

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

(我假设您sectionCell实体到Section实体之间存在反向关系。)

于 2012-10-15T17:37:30.073 回答