0
我已经创建了一个“日志条目”的表视图,根据输入的日期将其组织到节中。NSFetchedResultsSectionInfo名称的NSDateFormatter名称
我使用的核心数据所以为了做到这一点,我定义我的NSManagedObject以下只读属性计算:
- (NSString *)formattedDay {
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setTimeStyle:NSDateFormatterNoStyle];
[df setDateFormat:@"EEEE MMMM d, YYYY"];
NSString *dateString = [df stringFromDate:self.timestamp];
[df release];
return dateString;
}
然后我在NSFetchedResultsController使用sectionNameKeyPath:@"formattedDay"
。
这工作正常,但效率有点低,因为必须格式化每个日志行的字符串。有没有一种方法可以让我只有这个返回一个NSDate(而不是字符串),然后以某种方式访问的NSDate在titleForHeaderInSection:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return sectionInfo.name;
}
或以某种方式控制NSFetchedResultsController如何变成一个NSDate成sectionInfo.name?
谢谢。我认为我现在只是将其设置为静态并且延迟加载。 – Nimrod 2010-10-12 01:07:18