繁体   English   中英

如何从iPhone的UITableviewCell中的NSMutableArray加载图像?

[英]How to load Images from NSMutableArray in UITableviewCell in iPhone?

我需要从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做呢?

UIImageView *img = [[UIImageView alloc]initWithImage:[ d objectForKey:@"Image"]];
[cell.contentView addSubView:img];

使用以下代码设置图像:

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

这是您的NSMutableDictionary

如果数组中有图像,则将直接数组值用作波纹管图像。

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

或也像波纹管一样添加为单元格imageview。

cell.imageView.image = (UIImage *)[[arrData valueForKey:@"Image"] objectAtIndex:indexPath.row];

根据您的代码..尝试这个。

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];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM