提前致谢。在我的应用程序中,我有一个表格视图,其中我必须使用两种不同样式的自定义单元格,我制作了两个自定义单元格,在 tableView cellForRowAtIndexPath 方法中,我使用了两个单元格标识符,即使我尝试了两个部分。但它不工作。它给了我“EXE BAD Excess”或其他一些错误。下面是我的代码。
错误:thread1_EXE_BAD_Access(代码 = 2,地址 0 x 0)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
//CatIdentifier
static NSString *CellIdentiFier = @"CatIdentifier";
static NSString *Cell1IdentiFier = @"CatIdentifier1";
if (indexPath.section == 0)
{
CommitteCell *cell = ( CommitteCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentiFier];
if(cell == nil)
{
cell = ( CommitteCell *)[[[NSBundle mainBundle] loadNibNamed:@"CommitteeCell" owner:self options:nil] objectAtIndex:0];
}
if (indicator == 1)
{
cell.lblName.text = str;
}
else
{
cell.lblName.text = [arrayName objectAtIndex:indexPath.row];
cell.lblPost.text = [arrayPost objectAtIndex:indexPath.row];
cell.picimg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[arrayimage objectAtIndex:indexPath.row]]]];
}
cell.backgroundView = [[UIImageView alloc]init];
UIImage *img = [UIImage imageNamed:@"link-bg 2.png"];
((UIImageView *)cell.backgroundView).image = img;
return cell;
}
else
{
Committee2Cell *cell1 = (Committee2Cell *)[tableView dequeueReusableCellWithIdentifier:Cell1IdentiFier];
if(cell1 == nil)
{
cell1 = (Committee2Cell *)[[[NSBundle mainBundle] loadNibNamed:@"Committee2Cell" owner:self options:nil] objectAtIndex:0];
}
cell1.lblPost1.text = strPost;
cell1.txtName.text = strName;
cell1.backgroundView = [[UIImageView alloc]init];
UIImage *img = [UIImage imageNamed:@"link-bg 2.png"];
((UIImageView *)cell1.backgroundView).image = img;
return cell1;
}
}
表视图中的部分和部分方法中的行如下。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section)
{
case 0:
return [arrayName count]-1;
break;
case 1:
return 1;
break;
default:
break;
}
return 0;
}
请如果有人可以罚款我的错误在哪里。再次感谢。
数组和标签的数据如下。
-(void)NewsParser:(NSMutableDictionary *)dic { NSLog(@"dic = %@",dic);
arrayName = [[NSMutableArray alloc]init];
arrayPost = [[NSMutableArray alloc]init];
arrayimage= [[NSMutableArray alloc]init];
strPost = [[NSString alloc]init];
strName = [[NSString alloc]init];
strPost = [[dic valueForKey:@"post"]objectAtIndex:8];
strName = [[dic valueForKey:@"name"]objectAtIndex:8];
NSLog(@"Name = %@",strName);
NSLog(@"Post = %@",strPost);
for(int i=0;i<[dic count]-1;i++)
{
[arrayName addObject:[[dic valueForKey:@"name"]objectAtIndex:i]];
[arrayPost addObject:[[dic valueForKey:@"post"]objectAtIndex:i]];
[arrayimage addObject:[[dic valueForKey:@"pic"]objectAtIndex:i]];
}
NSLog(@"array = %@",arrayName);
NSLog(@"array = %@",arrayPost);
NSLog(@"array = %@",arrayimage);
[table1 reloadData];
}