核心数据获取结果控制器和自定义节标题
我熟悉管理表行的 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.
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.
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?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSFetchedResultsController 就是为此目的而设计的,因此您不必发明轮子。
当你初始化 NSFetchedResultsController 时,你应该考虑指定sectionNameKeyPath。该属性正是您自动生成该部分所需的属性。
对于你的情况,我会这样做:
你明白我的意思,如果你需要更多代码来澄清,请告诉我。
The NSFetchedResultsController is designed for this purpose, so you don't have to invent the wheel.
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:
You see what I mean, if you need more code for clarification, tell me.
您需要通过为您创建的 NSSet 来研究“多对多”关系,该 NSSet 是为您创建的,用于表示数据库中的“Route->>Day”路径。假设你将你的关系命名为 isTraversedOn,并且将日期->时间表命名为 isScheduled,它会类似于:
NSSet 仅保存指示对象的实际 id。
You need to research following the To Many relationship through the NSSet that is created for you to represent the Route->>Day path in your database. Assuming you named your relationship isTraversedOn, and the day->Schedule as isScheduled, it would be something like:
the NSSet just saves the actual id's of the indicated objects.