iphone Odd Problem when using a custom cell
- by Brodie4598
Please note where I have the NSLOG. All it is displaying in the log is the first three items in the nameSection. After some testing, I discovered it is displaying how many keys there are because if I add a key to the plist, it will log a fourth item in log.
nameSection should be an array of the strings that make up the key array in the plist file.
the plist file has 3 dictionaries, each with several arrays of strings. The code picks the dictionary I am working with correctly, then should use the array names as sections in the table and the strings en each array as what to display in each cell.
so if the dictionary i am working with has 3 arrays, NSLOG will display 3 strings from the first array:
2010-05-01 17:03:26.957 Checklists[63926:207] string0
2010-05-01 17:03:26.960 Checklists[63926:207] string1
2010-05-01 17:03:26.962 Checklists[63926:207] string2
then stop with: 2010-05-01 17:03:26.963 Checklists[63926:207] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFArray objectAtIndex:]: index (3) beyond bounds (3)'
if i added an array to the dictionary, it log 4 items instead of 3.
I hope this explanation makes sense...
-(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];
NSString *key = [keys objectAtIndex: section];
NSArray *nameSection = [names objectForKey:key];
static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
static NSString *ChecklistCellIdentifier = @"ChecklistCellIdentifier ";
ChecklistCell *cell = (ChecklistCell *)[tableView
dequeueReusableCellWithIdentifier: SectionsTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ChecklistCell"
owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[ChecklistCell class]])
cell = (ChecklistCell *)oneObject;
}
NSUInteger row = [indexPath row];
NSDictionary *rowData = [self.keys objectAtIndex:row];
NSString *tempString = [[NSString alloc]initWithFormat:@"%@",[nameSection objectAtIndex:row]];
NSLog(@"%@",tempString);
cell.colorLabel.text = [tempArray objectAtIndex:0];
cell.nameLabel.text = [tempArray objectAtIndex:1];
return cell;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
-(NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section{
NSString *key = [keys objectAtIndex:section];
return key;
}