For some reason, the tableView: titleForHeaderInSection:
method is causing the application to crash without giving any details as to why. I know it is this method because when I comment it out, the table loads, just without headers obviously.
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *monthArray = [NSArray arrayWithObjects:@"January", @"February", @"March", @"April", @"May", @"June", @"July", @"August", @"September", @"October", @"November", @"December", nil];
NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit;
NSDate *date = [NSDate date];
NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:date];
NSInteger year = [dateComponents year];
NSInteger month = [dateComponents month];
currentYear = [NSString stringWithFormat:@"%d", year];
nextYear = [NSString stringWithFormat:@"%d", year+1];
[dateComponents setMonth:month];
currentYearMonths = [[NSMutableArray alloc] init];
nextYearsMonths = [[NSMutableArray alloc] init];
for(uint i=month-1; i<=11; i++){
[currentYearMonths addObject:[monthArray objectAtIndex:i]];
}
for(uint i=0; i<month-1; i++){
[nextYearsMonths addObject:[monthArray objectAtIndex:i]];
}
[calendar release];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *sectionHeader = nil;
if(section == 0) {
sectionHeader = currentYear;
}
if(section == 1) {
sectionHeader = nextYear;
}
return sectionHeader;
}