Ilyés Ibrahim
Ilyés Ibrahim

Reputation: 25

Modify UIImageview in Xcode using URL

I tired to use this code in Xcode to modify a picture but nothing change

    UIImage *myimage= (UIImage *)[tableView viewWithTag:tag+1];

    NSURL *imageURL = [NSURL URLWithString:@"https://38.media.tumblr.com/avatar_c0deb2e1dd65_128.png"];


    dispatch_async(dispatch_get_global_queue(0,0), ^{
        NSData * data = [[NSData alloc] initWithContentsOfURL: imageURL];
        if ( data == nil ){
            return;

        }
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"dddddddd");

   __block myimage = [UIImage imageWithData: data];
        });

    });

Thanks.

Upvotes: 0

Views: 47

Answers (1)

Duncan C
Duncan C

Reputation: 131418

Your code is wrong. It should be something like this:

UIImageView *myImageView= (UIImageView *)[tableView viewWithTag:tag+1];

NSURL *imageURL = [NSURL URLWithString: 
  @"https://38.media.tumblr.com/avatar_c0deb2e1dd65_128.png"];
dispatch_async(dispatch_get_global_queue(0,0), ^
{
    NSData * data = [[NSData alloc] initWithContentsOfURL: imageURL];
    if ( data == nil )
    {
        return;
    }
    dispatch_async(dispatch_get_main_queue(), ^
    {
        NSLog(@"dddddddd");

        UIImage *myImage = [UIImage imageWithData: data];
        myImageView.image = myImage;
    });
});

Upvotes: 1

Related Questions