简体   繁体   English

UITableView中带有NSFetchedResultsController的附加部分

[英]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.

相关问题 将NSFetchedResultsController与UITableView中的特定部分相关联 - Associate NSFetchedResultsController with specific section in UITableView 具有NSFetchedResultsController的UITableView保留没有对象的节的标题 - UITableView with NSFetchedResultsController keep header for section without objects 如何在NSFetchedResultsController的部分中添加其他信息 - How to add additional informations in NSFetchedResultsController's section 从NSFetchedResultsController中删除部分时更新UITableView - update UITableView when section is removed from NSFetchedResultsController 带有NSFetchedResultsController的UITableView:对每个部分彼此独立地排序 - UITableView with NSFetchedResultsController: Sort each section independently of each other iOS-将单元格添加到带有核心数据和NSFetchedResultsController的空UITableView部分 - iOS - Add a cell to empty UITableView Section w/ Core Data and NSFetchedResultsController 使用 NSFetchedResultsController 的 UITableView 部分中的意外标题视图 - Unexpected Header View in UITableView's section using NSFetchedResultsController UITableView的QuickDialog和NSFetchedResultsController - QuickDialog and NSFetchedResultsController for a UITableView 刷新不绑定到uitableview的nsfetchedresultscontroller - refreshing an nsfetchedresultscontroller not tied to a uitableview 在UITableView的一部分上使用NSFetchedResultsController - Using NSFetchedResultsController on a part of UITableView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM