0

i want to set uiimage to a variable outside the scope of function .i tried the code below but it doesn't work . code below is used in custom uitable view cell class . so i just cannot alloc and init it . as this will cause to initialize it every time cell is displayed/ scrolled

 uiimage *img;
    [manager downloadWithURL:[NSURL URLWithString:friendData.picUrl] options:SDWebImageRefreshCached progress:^(NSInteger receivedSize, NSInteger expectedSize) {

    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {

        img =image; ////this is not working !!



    }];


    dispatch_async(dispatch_get_main_queue(), ^{


        [cell.profileImage setImage:img];   //and off course this wont work too

    });
warzone_fz
  • 472
  • 1
  • 9
  • 24

3 Answers3

1

I think you may just need to set __block UIImage image = nil;

dmerlea
  • 894
  • 4
  • 12
0

You can initialize the image1 with any other initializing methods: Try this one:

image1 = UIImage.init(CGImage:image.CGImage);

Initializer method will create new object as per this document.

I haven't tried it. Please try if it works. If not working just comment me, I may find other solution.

Shanmugaraja G
  • 2,778
  • 4
  • 31
  • 47
0

you need to allocate image1 to make it work out of the function.try this

image1 = [[UIImage alloc] initWithCGImage: image.CGImage];
Mounika Vangala
  • 396
  • 2
  • 3
  • 14