如果图像视图无法从给定的URL获取图像,如何获取任何消息?

时间:2015-08-10 12:47:23

标签: ios objective-c web-services grand-central-dispatch

我从网上抓取网址,如果图片视图无法从给定网址获取图片,我想显示任何消息。

这是我的代码。

NSString * image1 = [WebArray objectForKey:@"image_url"];

NSString * image2 = [[tempArray objectAtIndex:0]objectForKey:@"user_image"];

dispatch_queue_t imageQueue = dispatch_queue_create("Image Queue", NULL);


    dispatch_async(imageQueue, ^{

        NSURL *url = [NSURL URLWithString:image1];
        NSData *imageData = [NSData dataWithContentsOfURL:url];
        UIImage *image = [UIImage imageWithData:imageData];

        NSURL *url1 = [NSURL URLWithString:image2];
        NSData *imageData1 = [NSData dataWithContentsOfURL:url1];
        UIImage *image11 = [UIImage imageWithData:imageData1];

        dispatch_async(dispatch_get_main_queue(), ^{
            [user_image setImage:image];
            [self.tag_user_img setImage:image11];

        });
    });

2 个答案:

答案 0 :(得分:4)

 check image view is empty or not using
if(CGSizeEqualToSize(imageView.image.size, CGSizeZero))
{
 show alert here....
 }

答案 1 :(得分:1)

dispatch_async(dispatch_get_main_queue(), ^{

    if(!image)
    {
       // show your message
    }

    else
    {
            [user_image setImage:image];
    }

});