I actually got it working...whether or not it's the best method is open for discussion. Here is the code I came up with:
- (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]];
}
monthList = [[NSArray alloc] initWithArray:monthArray];
[calendar release];
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if([nextYearsMonths count] == 0)
return 1;
else
return 2;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if(section == 0){
return currentYear;
}else if(section == 1){
return nextYear;
}
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0)
return [currentYearMonths count];
if(section == 1)
return [nextYearsMonths count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
int section = [indexPath indexAtPosition:0];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
int monthIndex = [indexPath indexAtPosition: [indexPath length] - 1];
switch (section) {
case 0:
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [currentYearMonths objectAtIndex:monthIndex];
break;
case 1:
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [nextYearsMonths objectAtIndex:monthIndex];
break;
}
return cell;
}