[英]Additional section in UITableView with NSFetchedResultsController
I am currently implementing a UITableViewController with an NSFetchedResultsController. 我目前正在使用NSFetchedResultsController实现UITableViewController。 It fetches some objects from CoreData and displays them as rows in one section as expected.
它从CoreData中获取一些对象,并按预期将它们显示为一行中的一行。
Now, I would like to have one additional section with exactly one row that displays aggregated information about the fetched objects. 现在,我想再增加一个部分,其中只有一行显示有关所获取对象的汇总信息。
From what I know, one NSFetchedResultsController can only have one fetch request, but I would have to use another one to get the aggregated information. 据我所知,一个NSFetchedResultsController只能有一个提取请求,但是我将不得不使用另一个来获取汇总信息。
Perhaps I should use one NSFetchedResultsController for the Overall section and another one for the single object section, but this feels kind of strange to me. 也许我应该为“总体”部分使用一个NSFetchedResultsController,为单个对象部分使用另一个,但是这对我来说有点奇怪。
What do you think? 你怎么看?
You may consider to use one fetchedResultController. 您可能考虑使用一个fetchedResultController。 And add some observer functions in the delegate of fetchedResultController:
并在fetchedResultController的委托中添加一些观察器函数:
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller{
[self updateAggregatedInformation : basedOnFecthedObjects]; //with collection keypath methods;
[self updateTableView];
} }
There is a little overhead in the tableView DataSource, but gain in performance. tableView数据源中有一些开销,但可以提高性能。
I just solved the problem and it was more easy than I thought. 我只是解决了这个问题,这比我想的要容易。
The NSFetchedResultsControllerDelegate receives messages from the FRC and so the delivered IndexPath.section attributes have be adapted according to the tableView. NSFetchedResultsControllerDelegate接收来自FRC的消息,因此已根据tableView调整了传递的IndexPath.section属性。 The same needs to be done the other way around when the tableView calls the FRC to create cells that are backed up by the fetched entities.
当tableView调用FRC创建由获取的实体备份的单元格时,需要做其他的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.