2012-11-06 36 views
1

我需要從自服務url.I加載NSMutableArray LAOD一個圖像可以檢索XML的圖像標記response.Now我想在UITableViewCell如何從iPhone中的UITableviewCell中加載NSMutableArray中的圖像?

我的陣列看起來像這樣的形象:

(
{ 
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

是的,它是在陣列中,因爲我已經給出了 – Honey

+0

以上的數組響應,您需要在xml響應中傳遞圖像url而不是傳遞圖像名稱。 –

回答

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

使用下面的代碼來設置影像:

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

這裏d是NSMutableDictionary如果你有你的數組中的圖像,然後使用直接序列值像波紋管一圖像

+0

但是我收到錯誤「Program received Signal SIGABRT」..可能是什麼原因。? – Honey

+0

控制檯上是否有任何錯誤日誌? –

+0

發送到實例的無法識別的選擇器 – Honey

0

。 。

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

或者也可以像下圖一樣添加一個像cellview的圖像..

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

但我收到錯誤「Program received signal」SIGABRT「at this line:UIImageView * img = [[UIImageView alloc] initWithImage:[yourArray objectAtIndex:indexPath.row]]; I m添加它在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {}事件..Y是如此..? – Honey

+0

你的數組的值是什麼.. ??整個數組? ? –

+0

NAME = 「奧蘭多」; 圖片= 「46b6daca-3.png」; 狀態=佛羅里達; },{ 名稱 = 「約翰」; 圖片= 「9251bfe5-D.JPG」; 狀態=佛羅里達州; }, { Name =「Michael」; 圖片=「95f27b86-8.jpg」;州=佛羅里達州; } )我在陣列的每個對象中有更多的字段 – Honey

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]; 
相關問題