我能够将单个图像转换为UITableViewCell。这是我需要的任务是将两个图像放入UITableViewCell。我在下面粘贴的代码是用来解析一个图像。建议我对Get 2 images进行更改。
jsonDict = [jsonArr objectAtIndex:indexPath.row];
NSLog(@"imagess%@",jsonDict);
cell.textLabel.text = [jsonDict objectForKey:@"ImageName"];
cell.textLabel.textAlignment=NSTextAlignmentRight;
NSData *imgData = [NSData dataWithBase64EncodedString:[jsonDict objectForKey:@"ImageData"]];
cell.imageView.image = [UIImage imageWithData:imgData];
提前致谢。
答案 0 :(得分:2)
最后我达到了目标,在单个UITableViewCell中显示两个已解析的图像 我使用的代码是
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MyCell"];
if (cell==nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"];
UIImageView *imageView1=[[UIImageView alloc]init];
imageView1.frame=CGRectMake(0, 0,50,cell.frame.size.height);
imageView1.tag=1000;
[cell.contentView addSubview:imageView1];
UIImageView *imageView2=[[UIImageView alloc]init];
imageView2.frame=CGRectMake(cell.frame.size.width-50, 0, 50,cell.frame.size.height);
imageView2.tag=2000;
[cell.contentView addSubview:imageView2];
}
jsonDict = [jsonArr objectAtIndex:indexPath.row];
NSLog(@"imagess%@",jsonDict);
cell.textLabel.text = [jsonDict objectForKey:@"ImageName"];
cell.textLabel.textAlignment=NSTextAlignmentCenter;
if ([jsonDict objectForKey:@"RefImageData"] == [NSNull null]) {
// photo is null
NSData *imgData = [NSData dataWithBase64EncodedString:[jsonDict objectForKey:@"ImageData"]];
UIImageView *imageView=(UIImageView *)[cell.contentView viewWithTag:1000];
imageView.image=[UIImage imageWithData:imgData];
}
else {
// photo isn't null
NSData *imgData = [NSData dataWithBase64EncodedString:[jsonDict objectForKey:@"ImageData"]];
NSData *refimage=[NSData dataWithBase64EncodedString:[jsonDict objectForKey:@"RefImageData"]];
UIImageView *imageView=(UIImageView *)[cell.contentView viewWithTag:1000];
imageView.image=[UIImage imageWithData:imgData];
UIImageView *imageView2=(UIImageView *)[cell.contentView viewWithTag:2000];
imageView2.image=[UIImage imageWithData:refimage];
}
return cell;
答案 1 :(得分:1)
您需要创建一个自定义UITableViewCell
子类,其中包含两个图像视图。然后你可以像在这里一样从你的json中分配两个图像。
Apple provides an example how you can do that,还有很多教程,只搜索“自定义uitableviewcell子类教程”。