[英]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.