I'm trying to fill out a table. The descriptions are filled out correctly, but the titles are the same for all sections. I have no idea what's wrong
here's my code:
Code:
#import "CourseDirectory.h"
@implementation CourseDirectory
@synthesize courseTable, courseTypes, courseTypeDescription;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
//load data from file
NSString *path = [[NSBundle mainBundle] pathForResource:@"CourseTypes" ofType:@"plist"];
//initialize the dictionary
NSDictionary *dic = [[NSDictionary alloc] initWithContentsOfFile:path];
self.courseTypeDescription = dic;
NSArray *array = [self.courseTypeDescription allKeys];// sortedArrayUsingSelector:@selector(compare:)];
self.courseTypes = array;
[super viewDidLoad];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSString *courseType = [self.courseTypes objectAtIndex:section];
NSArray *courseSection = [self.courseTypeDescription objectForKey:courseType];
return [courseSection count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.courseTypes count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
//configure the cell here
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
//NSString *courseType = [self.courseTypes objectAtIndex:[indexPath section]];
NSString *courseType = [self.courseTypes objectAtIndex:[indexPath section]];
NSArray *courseSection = [self.courseTypeDescription objectForKey:courseType];
cell.textLabel.text = [courseTypes objectAtIndex:[indexPath row]];
cell.detailTextLabel.text = [courseSection objectAtIndex:[indexPath row]];
return cell;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return nil;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
#warning complete
}
edit: nvm fixed it