【发布时间】:2010-04-17 21:15:12
【问题描述】:
在我的核心数据应用程序中,我使用的是 FetchedResultsController。通常要在 UITableView 中设置标题的标题,您可以像这样实现以下方法:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[<#Fetched results controller#> sections] objectAtIndex:section];
return [sectionInfo name];
}
其中 [sectionInfo name] 返回一个 NSString。
我的 sectionKeyPath 基于 NSDate,除了它给我的部分标题是原始日期描述字符串(例如 12/12/2009 12:32:32 +0100)之外,这一切都很好,看起来有点像把标题弄乱了!
所以我想在此使用日期格式化程序来制作一个不错的标题,例如“2010 年 4 月 17 日”,但我不能使用 [sectionInfo name] 来做到这一点,因为这是 NSString!有什么想法吗?
非常感谢
【问题讨论】:
-
NSDateFormatter 的构建和执行非常昂贵;我会将它作为你的 tableview 的实例变量,这样你就不会在每次获取节标题时都构建它。
标签: iphone nsdate nsfetchedresultscontroller nsdateformatter