1

我需要NSMutableArray加载一个从服务 url 加载的图像。我可以从 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 做呢?

4

4 回答 4

0
UIImageView *img = [[UIImageView alloc]initWithImage:[ d objectForKey:@"Image"]];
[cell.contentView addSubView:img];
于 2012-11-06T10:26:39.383 回答
0

if you have images in your array then use direct array value as a image like bellow..

UIImageView *img = [[UIImageView alloc]initWithImage:[[arrData valueForKey:@"Image"] objectAtIndex:indexPath.row];
 img.frame = SetFrameHere;// 
[cell.contentView addSubView:img];

or also add as a cell imageview like bellow..

cell.imageView.image = (UIImage *)[[arrData valueForKey:@"Image"] objectAtIndex:indexPath.row];
于 2012-11-06T10:32:26.197 回答
0

使用以下代码设置图像:

UIImage *img = [[UIImage imageNamed:[d objectForKey:@"Image"];
cell.imageView.image = img;

这里 d 是你的NSMutableDictionary

于 2012-11-06T10:28:15.717 回答
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];
于 2012-11-06T10:46:12.527 回答