[英]How to load Images from NSMutableArray in UITableviewCell in iPhone?
I need to laod a image from NSMutableArray
which is loaded from service url.I can retrieve the image tag from XML response.Now I want that image in a UITableViewCell
我需要从
NSMutableArray
加载图像,该图像是从服务url加载的。我可以从XML响应中检索图像标签。现在,我希望该图像在UITableViewCell
My array looks like this : 我的数组看起来像这样:
(
{
Image="46b6daca-3.png";
}
{
Image="9251bfe5-d.jpg";
}
)
How can I load each image in a seperate UITableViewCell
? 如何将每个图像加载到单独的
UITableViewCell
?
For creating a UILabel I knew it is like this : 对于创建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];
How can I do it for UIImage? 如何为UIImage做呢?
UIImageView *img = [[UIImageView alloc]initWithImage:[ d objectForKey:@"Image"]];
[cell.contentView addSubView:img];
Use the following code for setting the image: 使用以下代码设置图像:
UIImage *img = [[UIImage imageNamed:[d objectForKey:@"Image"];
cell.imageView.image = img;
Here d is your NSMutableDictionary
这是您的
NSMutableDictionary
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.. 或也像波纹管一样添加为单元格imageview。
cell.imageView.image = (UIImage *)[[arrData valueForKey:@"Image"] objectAtIndex:indexPath.row];
as per you code.. try this. 根据您的代码..尝试这个。
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.