ios - UITableView 中带有 NSFetchedResultsController 的附加部分

标签 ios swift

我目前正在使用 NSFetchedResultsController 实现 UITableViewController。它从 CoreData 中获取一些对象,并按预期将它们显示为一个部分中的行。

现在,我想要一个额外的部分,其中只有一行显示有关所获取对象的聚合信息。

据我所知,一个 NSFetchedResultsController 只能有一个获取请求,但我必须使用另一个请求来获取聚合信息。

也许我应该为整体部分使用一个 NSFetchedResultsController,为单个对象部分使用另一个 NSFetchedResultsController,但这对我来说有点奇怪。

你觉得怎么样?

最佳答案

您可以考虑使用一个 fetchedResultController。并在fetchedResultController的委托(delegate)中添加一些观察者函数:

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller{
[self updateAggregatedInformation : basedOnFecthedObjects]; //with collection keypath methods;
[self updateTableView];

}

tableView 数据源有一点开销,但性能有所提高。

关于ios - UITableView 中带有 NSFetchedResultsController 的附加部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52737811/

相关文章:

ios - 如何更改 imagepickercontroller ios 状态栏的颜色?

ios - SDWebImage 下载但不显示图像

ios - 为什么滚动 UIWebView *感觉* 与滚动任何其他 UIScrollView 如此不同?

ios - 一旦屏幕在实际设备中被锁定,LockScreen Player 就不会出现。

ios - 不使用dispatch_once_t转换Swift 3代码

ios - 在 segue 中使用类时遇到问题

ios - Firebase Deeplink 未触发应用程序 :continueUserActivity:restorationHandler, Swift 4.2 Xcode10。

html - 如何在 iPhone 中将 Html 标签转换为纯文本

swift - 应用程序关闭时动态链接不起作用,仅在后台运行时

swift - 如何在 Swift 的异步 block 中使用@autoclosure 参数?