iphone - 为什么图像没有显示在 UIImageView 中

标签 iphone ios cocoa-touch ios4 uiimageview

我在下载远程图像并通过 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/

相关文章:

iphone - 在越狱的 iPhone 上,如何以 root 身份运行命令?

ios - iOS 共享实例在哪里释放

ios - UITableView 在不应该的时候将触摸事件传递给 superview

cocoa-touch - 主要的 Grand Central Dispatch 队列是串行的还是并发的?

ios - UITableViewController 在 iOS7 中删除行后忽略点击

iphone - iphone safari 中的部分黑色背景

iphone - iPhone 模拟器音频仅适用于 44100Hz、22050Hz 和 11025Hz

iphone - 如何给图像赋值

ios - 无法在 iPhone 内置 map 应用程序中显示路线

ios - 如何处理 phonegap cordova 上的 iOS 通知回调?