views:

433

answers:

0

Hello,

I am trying to create a grouped table view from a plist that contains a dictionary (code only no NIB). The dictionary contains several arrays and each array several strings. I can get the grouped table to work, BUT only if I include an index along the right side. Not sure why. The code seems to be bonking at the first line of the cellForRowAtIndexPath when I comment out the sectionIndexTitlesForTableView method. Any ideas?

Header

#import <UIKit/UIKit.h>

@interface ChartTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
    NSDictionary *dict;
    NSArray *list;
}

@property (nonatomic, retain) NSDictionary *dict;
@property (nonatomic, retain) NSArray *list;

@end

Portion of Implementation

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return ([list count] > 0) ?[list count] : 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([list count] == 0) {
     return 0;
    }
    NSString *key =[list objectAtIndex:section];
    NSArray *nameSection = [dict objectForKey:key];
    return [nameSection count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *key =[list objectAtIndex:indexPath.section];
    NSArray *nameSection = [dict objectForKey:key];

    static NSString *SectionsTableIdentifier = @"SectionsTableIndentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier];
    if (cell == nil) {
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SectionsTableIdentifier] autorelease];
    }
    cell.text = [nameSection objectAtIndex:indexPath.row];
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if ([list count] == 0) {
     return @"";
    }
    NSString *key =[list objectAtIndex:section];
    return key;
}

/* Crashes when I COMMENT this method, works fine if uncommented but includes index which is unwanted
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return list;
}
*/