It's best to create a standard structure like (personally, i'd suggest the following):
- Array that contains multiple dictionaries
- Each dictionary contains 2 keys
- Day is a
key and, say, June 20, is it's value
- Events is a
key and, it's value is an array object
- This array is a collection of strings that will basically be the content for these days
Example:
Possible UITableViewController subclass methods
- (void)viewDidLoad
{
[super viewDidLoad];
arrTest = @[
@{@"Day":@"June 20",
@"Events":@[@"Repair window pane", @"Buy food for Elephant", @"Pay credit card dues"]},
@{@"Day":@"July 20",
@"Events":@[@"Repair window frame", @"Buy alot more food for Elephant", @"Pay credit card dues dues"]},
@{@"Day":@"May 1",
@"Events":@[@"Replace entire window", @"Sell Elephant, Get Cat", @"Return credit card"]},
@{@"Day":@"May 10",
@"Events":@[@"Take bath", @"Shave", @"Get new credit card"]}
];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//get count of main array (basically how many days)
return arrTest.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//get count of number of events in a particular day
//old style
//return [[[arrTest objectAtIndex:section] objectForKey:@"Events"] count];
return [arrTest[section][@"Events"] count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
//get value of the "Day" key (June 20 / July 20 ...)
//old style
//return [[arrTest objectAtIndex:section] objectForKey:@"Day"];
return arrTest[section][@"Day"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//old style
//NSString *strDayEvent = [[[arrTest objectAtIndex:indexPath.section] objectForKey:@"Events"] objectAtIndex:indexPath.row];
NSString *strDayEvent = arrTest[indexPath.section][@"Events"][indexPath.row];
[cell.textLabel setText:strDayEvent];
return cell;
}
testis the section name but from where will you be displaying the data for the respective dates? if you've haven't reached there yet, you could consider using an carefully structured array of dictionaries and arrays.