This should do the trick for you:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *rawDateStr = [[[self.fetchedResultsController sections] objectAtIndex:section] name];
// Convert rawDateStr string to NSDate...
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZ"];
NSDate *date = [formatter dateFromString:rawDateStr];
// Convert NSDate to format we want...
[formatter setDateFormat:@"d MMMM yyyy"];
NSString *formattedDateStr = [formatter stringFromDate:date];
return formattedDateStr;
}
[EDIT]
Jus saw your comment and for what you are trying to achieve, you could create a transient NSDate
attribute (non persistent) that is formatted in a similar way to the above code (i.e. without H:mm:ss ZZZZ) and use that attribute as your sectionNameKeyPath
value.
So in a nutshell for a foo
object, with fooDate
and fooDateTransient
attributes, you would:
-
Get your
foo.fooDate
attribute -
Transform it using the code above (or similar) and assign the
NSDate
result tofoo.fooDateTransient
-
Use
fooDateTransient
as yoursectionNameKeyPath
when creating thefetchedResultsController
object.
PS: I haven’t tested this myself but should be worth a shot!
Good luck,
Rog