我有一個多重Imageview與標籤1,2,3,4 ...將圖像添加到UIImageView及其標籤
現在我想加載該圖像上的圖像與他們各自的標籤。
對於例如:如果6個Imageviews在那裏的話,
for(int i=0;i<6;i++)
{
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(xpos+10,20, 75, 45)];
xpos+=100;
imgView.tag=i;
if ([[msg_array objectAtIndex:i] valueForKey:@"Image"]) //Image is cached then assign it
{
imgView.image=[[msg_array objectAtIndex:i] valueForKey:@"Image"];
}
else //Image is not there download it..
{
if ([[msg_array objectAtIndex:i] valueForKey:@"Image"] length]!=0)
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
[self downloadImage_3:[[msg_array objectAtIndex:i] valueForKey:@"Merchant_SmallImage"] AtIndex:i];
});
}
}
}
//Downloads Images asynchronously..
-(void)downloadImage_3:(NSString*)ImageUrl AtIndex:(int)i{
if ([ImageUrl length]!=0)
{
UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:ImageUrl]]];
NSLog(@"img = %@",img);
imgView.image=img;
}
}
寫這之後,圖像越來越下載(日誌顯示的img
一些編碼值),但它沒有得到應用在其各自的ImageView。
請幫助,並提前致謝。
是你添加你的imageview作爲視圖的子視圖? –
使用圖像延遲加載從url加載圖像 – NANNAV