【发布时间】:2014-01-06 15:23:29
【问题描述】:
我有一个带有标签 1,2,3,4...的多个 Imageview...
现在我想用它们各自的标签在那个 Imageviews 上加载图像。
例如:如果有 6 个 Imageview,则
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 的一些编码值),但它没有应用于其各自的图像视图。
请帮助并提前致谢。
【问题讨论】:
-
您是否将您的图像视图添加为视图的子视图?
-
使用图片延迟加载从url加载图片
标签: ios iphone ipad uiimageview uiimage