加速 - [setImage:]使用UIImageView?

时间:2012-06-28 03:58:52

标签: iphone ios uiimageview uiimage

我目前正在开发一个应用程序,它包含图像下载并在滚动视图中显示大约20个图像。下载效果很好,从NSData到UIImage的转换也很好。但是,如果多次下载同时完成,我会遇到1秒延迟峰值,因此如果UIImageView的多个图像属性设置在非常接近的位置。我怎样才能减少这种滞后?

这是下载完成时调用的代码。这可以在1秒的间隔内调用20次左右。

// _imageDataQueue is a dispatch_queue created in the init method
dispatch_async(_imageDataQueue, ^{

    // data is an NSData object set when the download completes
    UIImage *image = [UIImage imageWithData:data];

    dispatch_async(dispatch_get_main_queue(), ^{

        if (image) {

            // this is stripped down, but it is just some simple logic
            // and eventually the image is set
            [theImageView setImage:image];

        } else {

            // called if there is no image and theImageView's image is set
            // to a cached image
            [theImageView setImage:someCachedUIImage];

        }

    });

});

也许我可以排队setImage调用?解决这个问题的最佳方法是什么?

0 个答案:

没有答案
相关问题