核心数据获取结果控制器和定制节头 [英] Core Data Fetched Results Controller and Custom Section Header

查看:146
本文介绍了核心数据获取结果控制器和定制节头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉NSFetchedResultsController管理表格行的常见和基本用法,但我有一个有趣的问题。

I am familiar with the common and basic use of a NSFetchedResultsController managing the rows of a table, but I have an interesting problem.

我的数据是这样组织的:日程< --- >>日< --- >>路线。我目前有一个表视图,其中包含具有提取控制器的计划,用于管理计划的创建和删除。现在我想为Routes / Days创建一个表视图。

My data is organized as such: Schedule <--->> Day <--->> Route. I currently have a table view that has Schedules with a fetch controller managing the creation and deletion of Schedules. I now want to create a table view for Routes/Days.

我想在每一行中列出一个Route,并创建与相关日。我可以通过抓取所有的路由,然后通过与相应的日期的反向关系将它们分割在一起,但我担心,那么我将无法利用fetch控制器委托方法更新表,管理对象更改。

I would like to list a Route on every row, and create custom section headers that correspond to information within the relevant Day. I could probably hack something together by fetching all the routes, and then sectioning them by the inverse relationship to there respective Day, but I am worried that then I will not be able to take advantage of the fetch controller delegate methods for updating the table when managed objects change.

有没有任何经验?关于如何前进的任何想法?

Does anyone have any experience with this? Any ideas on how to move forward?

感谢。

推荐答案

NSFetchedResultsController是为此目的设计的,所以你不必发明轮子。

The NSFetchedResultsController is designed for this purpose, so you don't have to invent the wheel.

初始化NSFetchedResultsController时,应考虑指定sectionNameKeyPath。

When you initialize your NSFetchedResultsController, you should consider specifying the sectionNameKeyPath. That property is exactly what you need to automatically generating the section for you.

在你的情况下,我会这样做:

In your case, I would do as follows:

NSEntityDescription: @"Route"
NSPredicate: @"day = %@"
NSFetchedResultsController: sectionNameKeyPath:@"route.day"

你看到我的意思,如果你需要更多的代码澄清,告诉我。

You see what I mean, if you need more code for clarification, tell me.

这篇关于核心数据获取结果控制器和定制节头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆