如何使用 NSFetchedResultsController 在日期之后生成部分
我提供了一个托管对象列表,其中每个对象都有一个 timeStamp 属性。我想使用 timeStamp 属性按时间顺序对列表进行排序,这是我使用 NSSortDescriptor 所做的。但我也想基于整个日期生成部分(每天一个部分)
下面将给我一个基于二阶差异的部分,该部分太多了:
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"timeStamp" cacheName:@"PatientDetailViewCache"];
有没有一种方法可以使用 NSFetchedResultsController 从 timeStamp 属性生成部分格式如 yy-MM-dd?
感谢您的帮助
基督徒
I am presenting a list of managed objects where each has a timeStamp property. I want to sort the list chronologically using the timeStamp property which i do with a NSSortDescriptor. But I also want to generate sections based on whole dates (one section for every day)
The following will give me one section based on second-differences which is too many sections:
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"timeStamp" cacheName:@"PatientDetailViewCache"];
Is there a way to generate sections from the timeStamp property with the NSFetchedResultsController that are formatted like yy-MM-dd?
Thanks for any help
Christian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是在子类 NSManagedObject 上为格式化日期创建一个属性并使用该属性进行排序。 SO 上有很多类似问题的问题。
从 NSFetchedResultsController 设置 UITableView 标头
一个 NSFetchedResultsController,日期为sectionNameKeyPath
但是在
awakeFromFetch:
中创建一个类范围的 NSDateFormater,如下所示:然后在该类属性的访问器中执行如下操作:
然后您获取的结果控制器是:
然后它将返回格式化日期并基于此进行排序。
The easiest way is on your subclassed NSManagedObject create a property for a formatted date and sort using that property. There are many questions on SO with similar questions.
Setting UITableView headers from NSFetchedResultsController
A NSFetchedResultsController with date as sectionNameKeyPath
But create a class wide NSDateFormater in the
awakeFromFetch:
like so:then in the accessor for that class property do something like this:
Then your fetched results controller is:
Then it will return the formatted date and sort based on that.