0

I am writing an app that displays images from url in a view. The idea is that when the view appears, image is dowloaded and it actualizes a UIImamgeView in the view.

I am using a Asyncrounse method in this way:

 -(void)downloadASyncro:(NSString*)urlLink{

        NSURL * imageURL = [NSURL URLWithString:urlLink];

        [self downloadImageWithURL:imageURL completionBlock:^(BOOL succeeded, UIImage *image) {
            if (succeeded) {

                NSLog(@"scaricaImmagineASyncro  Succeded=  %@",image);
                picView.image = image;
            }
            else {
                //default image
                picView.image = [UIImage imageNamed:@"icon_old.jpg"];

            }
        }];

     }

the downloadImageWithURL method is:

- (void)downloadImageWithURL:(NSURL *)url completionBlock:(void (^)(BOOL succeeded, UIImage *image))completionBlock
{
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [NSURLConnection sendAsynchronousRequest:request
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                               if ( !error )
                               {
                                   UIImage *image = [[UIImage alloc] initWithData:data];
                                   completionBlock(YES,image);
                               } else{
                                   completionBlock(NO,nil);
                               }
                           }];
}

When I call the method:

[self downloadASyncro:link];

and the operation sees end with success (NSLOG), picView.image = image; should actualize the view showing the image downloaded , should not it? But immage does not appear...

Any idea? Thanks in advance.

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
doxsi
  • 1,002
  • 19
  • 42

0 Answers0