我在下载远程图像并通过 UIImageView 对象的 'image' 属性将内容添加到 UIImageView 对象的简单代码时遇到问题。它不显示下载的图像,而是显示旧图片。有缓存负责吗?我已经重置了所有内容并删除了缓存文件,但仍然不明白为什么这个旧图像仍然显示。
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// Set appIcon and clear temporary data/image
UIImage *image = [[UIImage alloc] initWithData:self.activeDownload];
if (image.size.width != kAppIconHeight && image.size.height != kAppIconHeight)
{
CGSize itemSize = CGSizeMake(kAppIconHeight, kAppIconHeight);
UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image drawInRect:imageRect];
self.image_view.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
else
{
self.image_view.image = image;
}
self.activeDownload = nil;
[image release];
// Release the connection now that it's finished
self.imageConnection = nil;
// call our delegate and tell it that our icon is ready for display
[delegate appImageDidLoad:self.indexPathInTableView];
}
最佳答案
设置图像属性后尝试调用[imageView setNeedsDisplay]。
关于iphone - 为什么图像没有显示在 UIImageView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7456127/