I have a sectioned table view that will show events for each month. Each section is a month and I'm wanting to make each section expandable and collapsible to minimize the amount of scrolling the user has to do to get to the info they want. Can someone help point me in the right direction? Here is what I have so far.
Code:
//
// Events.m
// KFBNewsroom
//
// Created by Adam Rayborn on 12/12/12.
// Copyright (c) 2012 com.kfb. All rights reserved.
//
#import "Events.h"
#import "CustomCellBackground.h"
@interface Events ()
@end
@implementation Events
{
NSMutableArray *jan;
NSMutableArray *feb;
NSMutableArray *mar;
NSMutableArray *apr;
NSMutableArray *may;
NSMutableArray *june;
NSMutableArray *july;
NSMutableArray *aug;
NSMutableArray *sept;
NSMutableArray *oct;
NSMutableArray *nov;
NSMutableArray *dec;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.title = NSLocalizedString(@"Events", @"Events");
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
jan = [NSMutableArray arrayWithObjects:@"3\n\n113th Congress Convenes\nWashington, D.C.", @"6-8\n\nAmerican Forage & Grassland Council Annual Conference\nMarriott River Center\nCovington, KY", @"7-8\n\nJoint Meeting: KY State Horticulture Society, KY Vegetable Growers Association, KY Vineyard Society, KY Farmers Market Association\nEmbassy Suites\nLexington, KY", @"8\n\nKY General Assembly Part I Convenes\nFrankfort, KY", @"10-12\n\nKentucky Cattlemen's Association & Ag Industry Convention & Trade Show\nConvention Center\nLexington, KY", @"11\n\nKentucky Horse Council Annual Meeting\nConvention Center\nLexington, KY", @"13-16\n\nAFBF 94th Annual Meeting\nNashville, TN", @"16\n\nAFBF Board & Affiliated Meetings\nNashville, TN", @"18\n\nKentucky Commodity Conference\nHoliday Inn\nBowling Green, KY", @"18-19\n\nKentucky Pork Producers Association Annual Meeting\nHoliday Inn\nBowling Green, KY", @"21-22\n\nLEAD Meeting\nLexington, KY", @"22\n\nOrientation for New Directors\nState Office", @"23\n\nBoard of Directors Meetings: KFBF, KFB Investment Corporation, KFB Education Foundation, KFB Management Corporation\nStateOffice", @"23-25\n\nMid States Horticulture Expo\nKYInternational Convention Center\nLouisville, KY", @"24\n\nKFB Mutual Insurance Company Board of Directors Meeting\nState Office", @"24-25\n\nKentucky Landscape Industries Conference\nKYInternational Convention Center\nLouisville, KY", @"25-26\n\nYoung Farmer Leadership Conference\nMarriott Downtown\nLouisville, KY", @"30\n\nAgency Support & Marketing Tip Off Meeting\nRupp Arena\nLexington, KY", @"30\n\nAg Expo\nHines Center\nOwensboro, KY", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 12;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0)
{
return @"January";
}
else if (section == 1)
{
return @"February";
}
else if (section == 2)
{
return @"March";
}
else if (section == 3)
{
return @"April";
}
else if (section == 4)
{
return @"May";
}
else if (section == 5)
{
return @"June";
}
else if (section == 6)
{
return @"July";
}
else if (section == 7)
{
return @"August";
}
else if (section == 8)
{
return @"September";
}
else if (section == 9)
{
return @"October";
}
else if (section == 10)
{
return @"November";
}
else if (section == 11)
{
return @"December";
}
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
{
return [jan count];
}
else if (section == 1)
{
return [feb count];
}
else if (section == 2)
{
return [mar count];
}
else if (section == 3)
{
return [apr count];
}
else if (section == 4)
{
return [may count];
}
else if (section == 5)
{
return [june count];
}
else if (section == 6)
{
return [july count];
}
else if (section == 7)
{
return [aug count];
}
else if (section == 8)
{
return [sept count];
}
else if (section == 9)
{
return [oct count];
}
else if (section == 10)
{
return [nov count];
}
else if (section == 11)
{
return [dec count];
}
return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 175;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *mbTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mbTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:mbTableIdentifier];
cell.textLabel.font=[UIFont systemFontOfSize:16.0];
}
cell.backgroundView = [[CustomCellBackground alloc] init];
cell.selectedBackgroundView = [[CustomCellBackground alloc] init];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.highlightedTextColor = [UIColor darkGrayColor];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.textLabel.numberOfLines = 0;
cell.textLabel.text = [jan objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
@end