iphone – 从NSFetchedResultsController设置UITableView标头

iphone – 从NSFetchedResultsController设置UITableView标头,第1张

概述我有一个NSFetchedResultsController,它从NSManagedObjectContext中获取对象.我正在使用结果来填充UITableView. 我正在使用这两个排序描述符进行过滤. NSSortDescriptor *lastOpened = [[NSSortDescriptor alloc] initWithKey:@"lastOpened" ascending 我有一个NSFetchedResultsController,它从NSManagedobjectContext中获取对象.我正在使用结果来填充UItableVIEw.

我正在使用这两个排序描述符进行过滤.

NSSortDescriptor *lastopened =     [[NSSortDescriptor alloc] initWithKey:@"lastopened" ascending:NO];NSSortDescriptor *TitleDescriptor =     [[NSSortDescriptor alloc] initWithKey:@"Title" ascending:YES];

当我创建NSFetchedResultsController时,我通过sectionnameKeyPath对这些节进行排序:@“lastopened”.

现在我的部分显示标准格式,如2009-07-02 20:51:27 -0400,因为没有两个可以同时打开,它们都是独一无二的.我需要它们来涵盖日期/时间范围,例如一整天,并且是人类可读的形式.像7月2日星期四那样的东西.

谢谢!

编辑:

这都在UItableVIEwController中.这是一些更多的代码.

- (Nsstring *)tableVIEw:(UItableVIEw *)tableVIEw  TitleForheaderInSection:(NSInteger)section {    // display the dates as section headings.    return [[[fetchedResultsController sections] objectAtIndex:section] name];}- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section {    ID <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];    return [sectionInfo numberOfObjects];}
解决方法 我最终在NSManagedobject子类中添加了一个新的属性日来获取格式化的日期字符串.

@property (nonatomic,Readonly) Nsstring * day;@property (nonatomic,retain) NSDateFormatter * dateFormatter

Sythesize dateFomatter.
 @synthesize dateFormatter;

我在awakeFromFetch和awakeFromInsert中初始化日期格式化程序.

self.dateFormatter = [[[NSDateFormatter alloc] init] autorelease];[self.dateFormatter setDateStyle:NSDateFormatterMediumStyle];

一天的访问者.

- (Nsstring *)day {  NSDate *date = self.startDate;  return [self.dateFormatter stringFromDate:date];}

然后我设置我的部分名称keypath来看日;您不需要对排序描述符进行任何更改.

总结

以上是内存溢出为你收集整理的iphone – 从NSFetchedResultsController设置UITableView标头全部内容,希望文章能够帮你解决iphone – 从NSFetchedResultsController设置UITableView标头所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1020568.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存