【发布时间】:2010-11-07 19:47:25
【问题描述】:
我有一个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];
}
【问题讨论】:
-
您是使用绑定来填充表格还是为 UITableView 编写了数据源?
-
提问者是为 iPhone 开发的,所以不能是 Bindings,因为 Cocoa Touch 中不存在。 developer.apple.com/IPhone/library/documentation/Miscellaneous/…
-
您应该通过将
NSPredicates设置为 Fetched 结果控制器来过滤掉结果,顺便说一句。您仍然可以使用多种方式进行排序,但如果您只想显示某些“属性为真”(即满足谓词)的某些对象,请使用 NSPredicates。
标签: iphone cocoa cocoa-touch core-data