Hi I'm fairly new to this SDK programming and am having a problem getting the data of the selected cell with this code populated from a plist. I've spent a few days trying to make it work and can't figure out what I need to do differently, so any help would be very much appreciated.
Code:
@implementation FlipsideViewController
@synthesize delegate;
@synthesize keys;
@synthesize names;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
self.title = @"Anaesthetic";
NSString *path = [[NSBundle mainBundle] pathForResource:@"TOC" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc]
initWithContentsOfFile:path];
self.names = dict;
NSLog(@"Log names: %@", names);
[dict release];
NSArray *array = [[names allKeys] sortedArrayUsingSelector:
@selector(compare:)];
self.keys = array;
NSLog(@"Log keys: %@", keys);
[array release];
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [keys count];
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [names objectForKey:key];
return [nameSection count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [names objectForKey:key];
static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SectionsTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SectionsTableIdentifier] autorelease];
}
cell.textLabel.text = [nameSection objectAtIndex:row];
NSString *cellText = [nameSection objectAtIndex:row];
NSLog(@"Log cellText: %@", cellText);
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [names objectForKey:key];
NSString *selectedCell = [nameSection objectAtIndex:row];
NSLog(@"Log selectedCell: %@", selectedCell);
//NSInteger dose = [rowData objectForKey:@"Dose"];
CalculatorViewController *calculatorViewController = [[CalculatorViewController alloc] initWithNibName:@"Lignocaine" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:calculatorViewController animated:YES];