为什么图像没有出现在UIImageView中

时间:2011-09-17 16:15:08

标签: iphone ios cocoa-touch ios4 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];
}

1 个答案:

答案 0 :(得分:1)

尝试在设置图像属性后调用[imageView setNeedsDisplay]。