我有包含记录的表格视图。问题是,当我们按照 1、2、3 等系列单击单元格时,它工作正常,但如果我们直接选择 2,它就会崩溃。这是我的代码。
我的 tableView 有多个部分,部分中有数据。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle=UITableViewCellSelectionStyleGray;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if (indexPath.section==0)
{
cell.textLabel.font=[UIFont fontWithName:@"Helvetical Bold" size:14];
cell.textLabel.textColor=[UIColor blackColor];
ObjectData*coffeeObj=[subCategoryArray objectAtIndex:indexPath.row];
cell.textLabel.text=coffeeObj.subCategoryTitle;
return cell;
}
else if (indexPath.section==1)
{
cell.textLabel.font=[UIFont fontWithName:@"Helvetical Bold" size:14];
cell.textLabel.textColor=[UIColor blackColor];
ObjectData*coffeeObj=[subCategoryArrayOne objectAtIndex:indexPath.row];
cell.textLabel.text=coffeeObj.subCategoryTitle;
return cell;
}
else {
cell.textLabel.font=[UIFont fontWithName:@"Helvetical Bold" size:14];
cell.textLabel.textColor=[UIColor blackColor];
ObjectData*coffeeObj=[subCategoryArrayTwo objectAtIndex:indexPath.row];
cell.textLabel.text=coffeeObj.subCategoryTitle;
return cell;
}}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString*title;
if (indexPath.section==0) {
ObjectData*coffeeObj=[subCategoryArray objectAtIndex:indexPath.row];
NSString*subCatID =coffeeObj.subCategoryID;
NSArray *tempArray =[[DataController staticVersion] startParsing:[NSString stringWithFormat:@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/getDetailData.php?subCatID=%@",subCatID]];
for (int i = 0; i<[tempArray count]; i++) {
id *item = [tempArray objectAtIndex:i];
NSDictionary *dict = (NSDictionary *) item;
ObjectData *theObject =[[ObjectData alloc] init];
[theObject setCatalogID:[dict objectForKey:@"CatalogID"]];
[theObject setContentType:[dict objectForKey:@"ContentType"]];
[theObject setContentTitle:[dict objectForKey:@"ContentTitle"]];
[theObject setContentDescription:[dict objectForKey:@"ContentDescription"]];
[theObject setContentSource:[dict objectForKey:@"ContentSource"]];
[detailArray addObject:theObject];
[theObject release];
theObject=nil;
}
int counting=[detailArray count];
NSLog(@"Counting is %d",counting);
ObjectData*data1=[detailArray objectAtIndex:indexPath.row];
NSString*content_Type=data1.contentType;
NSString*content_Description=data1.contentDescription;
NSString*content_Source=data1.contentSource;
NSString*content_Title=data1.contentTitle;
NSLog(@"Type is %@",content_Type);
NSLog(@"Description is %@",content_Description);
NSLog(@"Source is %@",content_Source);
CategoryDetailViewController*targetController=[[CategoryDetailViewController alloc]init];
targetController.content_Type=content_Type;
targetController.content_Description=content_Description;
targetController.content_Source=content_Source;
targetController.content_Title=content_Title;
[self.navigationController pushViewController:targetController animated:YES];
}
else if(indexPath.section==1){
ObjectData*coffeeObj=[subCategoryArrayOne objectAtIndex:indexPath.row];
NSString*subCatID =coffeeObj.subCategoryID;
NSArray *tempArray =[[DataController staticVersion] startParsing:[NSString stringWithFormat:@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/getDetailData.php?subCatID=%@",subCatID]];
for (int i = 0; i<[tempArray count]; i++) {
id *item = [tempArray objectAtIndex:i];
NSDictionary *dict = (NSDictionary *) item;
ObjectData *theObject =[[ObjectData alloc] init];
[theObject setCatalogID:[dict objectForKey:@"CatalogID"]];
[theObject setContentType:[dict objectForKey:@"ContentType"]];
[theObject setContentTitle:[dict objectForKey:@"ContentTitle"]];
[theObject setContentDescription:[dict objectForKey:@"ContentDescription"]];
[theObject setContentSource:[dict objectForKey:@"ContentSource"]];
[detailArrayOne addObject:theObject];
[theObject release];
theObject=nil;
}
ObjectData*data1=[detailArrayOne objectAtIndex:indexPath.row];
NSString*content_Type=data1.contentType;
NSString*content_Description=data1.contentDescription;
NSString*content_Source=data1.contentSource;
NSString*content_Title=data1.contentTitle;
NSLog(@"Type is %@",content_Type);
NSLog(@"Description is %@",content_Description);
NSLog(@"Source is %@",content_Source);
CategoryDetailViewController*targetController=[[CategoryDetailViewController alloc]init];
targetController.content_Type=content_Type;
targetController.content_Description=content_Description;
targetController.content_Source=content_Source;
targetController.content_Title=content_Title;
[self.navigationController pushViewController:targetController animated:YES];
}
else {
ObjectData*coffeeObj=[subCategoryArrayTwo objectAtIndex:indexPath.row];
NSString*subCatID =coffeeObj.subCategoryID;
NSArray *tempArray =[[DataController staticVersion] startParsing:[NSString stringWithFormat:@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/getDetailData.php?subCatID=%@",subCatID]];
for (int i = 0; i<[tempArray count]; i++) {
id *item = [tempArray objectAtIndex:i];
NSDictionary *dict = (NSDictionary *) item;
ObjectData *theObject =[[ObjectData alloc] init];
[theObject setCatalogID:[dict objectForKey:@"CatalogID"]];
[theObject setContentType:[dict objectForKey:@"ContentType"]];
[theObject setContentTitle:[dict objectForKey:@"ContentTitle"]];
[theObject setContentDescription:[dict objectForKey:@"ContentDescription"]];
[theObject setContentSource:[dict objectForKey:@"ContentSource"]];
[detailArrayTwo addObject:theObject];
[theObject release];
theObject=nil;
}
int counting=[detailArray count];
NSLog(@"Counting is %d",counting);
ObjectData*data1=[detailArrayTwo objectAtIndex:indexPath.row];
NSString*content_Type=data1.contentType;
NSString*content_Description=data1.contentDescription;
NSString*content_Source=data1.contentSource;
NSString*content_Title=data1.contentTitle;
NSLog(@"Type is %@",content_Type);
NSLog(@"Description is %@",content_Description);
NSLog(@"Source is %@",content_Source);
CategoryDetailViewController*targetController=[[CategoryDetailViewController alloc]init];
targetController.content_Type=content_Type;
targetController.content_Description=content_Description;
targetController.content_Source=content_Source;
targetController.content_Title=content_Title;
[self.navigationController pushViewController:targetController animated:YES];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}