答えられなかったこの前の質問を後回しにしています-日付セクションのタイトルが機能しません
誰かが私(およびコミュニティ)がAppleのプロジェクトDateSectionTitles(http://developer.apple.com/library/ios/#samplecode/DateSectionTitles/Introduction/Intro.html)を月セクションのタイトルから日セクションに適切に変換するのに役立つコードを提供できますか?タイトル?
私の多くの試みから、それは基本的に2つの部分を変更することに帰着すると信じています。
(1)RootViewController.mのtitleForHeaderInSection
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> theSection = [[fetchedResultsController sections] objectAtIndex:section];
/*
Section information derives from an event's sectionIdentifier, which is a string representing the number (year * 1000) + month.
To display the section title, convert the year and month components to a string representation.
*/
static NSArray *monthSymbols = nil;
if (!monthSymbols) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setCalendar:[NSCalendar currentCalendar]];
monthSymbols = [[formatter monthSymbols] retain];
[formatter release];
}
NSInteger numericSection = [[theSection name] integerValue];
NSInteger year = numericSection / 1000;
NSInteger month = numericSection - (year * 1000);
NSString *titleString = [NSString stringWithFormat:@"%@ %d", [monthSymbols objectAtIndex:month-1], year];
return titleString;
}
(2)およびEvent.mのsectionIdentifier
- (NSString *)sectionIdentifier {
// Create and cache the section identifier on demand.
[self willAccessValueForKey:@"sectionIdentifier"];
NSString *tmp = [self primitiveSectionIdentifier];
[self didAccessValueForKey:@"sectionIdentifier"];
if (!tmp) {
/*
Sections are organized by month and year. Create the section identifier as a string representing the number (year * 1000) + month; this way they will be correctly ordered chronologically regardless of the actual name of the month.
*/
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit ) fromDate:[self timeStamp]];
tmp = [NSString stringWithFormat:@"%d", ([components year] * 1000) + [components month]];
[self setPrimitiveSectionIdentifier:tmp];
}
return tmp;
}
前もって感謝します!