我需要从服务网址加载NSMutableArray
的图像。我可以从XML响应中检索图像标记。现在我想要UITableViewCell
我的数组看起来像这样:
(
{
Image="46b6daca-3.png";
}
{
Image="9251bfe5-d.jpg";
}
)
如何以单独UITableViewCell
?
为了创建UILabel,我知道它是这样的:
NSMutableDictionary *d = (NSMutableDictionary *) [arr objectAtIndex:indexPath.row];
UILabel *line1=[[UILabel alloc]initWithFrame:CGRectMake(10, 68, 320,10)];
line1 .font=[UIFont fontWithName:@"arial" size:12];
[line1 setTextAlignment:UITextAlignmentLeft];
[line1 setText:[d valueForKey:@"Name"]];
line1.tag=113;
[cell addSubview:line1 ];
[line1 release];
我如何为UIImage做到这一点?
答案 0 :(得分:0)
UIImageView *img = [[UIImageView alloc]initWithImage:[ d objectForKey:@"Image"]];
[cell.contentView addSubView:img];
答案 1 :(得分:0)
使用以下代码设置图像:
UIImage *img = [[UIImage imageNamed:[d objectForKey:@"Image"];
cell.imageView.image = img;
此处d是您的NSMutableDictionary
答案 2 :(得分:0)
如果您的阵列中有图像,则使用直接数组值作为图像,如下图..
UIImageView *img = [[UIImageView alloc]initWithImage:[[arrData valueForKey:@"Image"] objectAtIndex:indexPath.row];
img.frame = SetFrameHere;//
[cell.contentView addSubView:img];
或者也可以添加为像bellow一样的细胞图像视图。
cell.imageView.image = (UIImage *)[[arrData valueForKey:@"Image"] objectAtIndex:indexPath.row];
答案 3 :(得分:0)
根据您的代码..试试这个。
NSMutableDictionary *d = (NSMutableDictionary *) [arr objectAtIndex:indexPath.row];
UIImageView *img = [[UIImageView alloc]initWithImage:[ d objectForKey:@"Image"]];
img,frame = CGRectMake("Set frame")]
[cell.contentView addSubView:img];
[img release];