0

I am using SDWebImageImagemanger to hadnle asyn call and caching. However it does not return the image to the cell.imageview.view. Here is the code:

        NSString *imageURLString=[[tableData objectAtIndex:indexPath.row] valueForKey:@"picture"];
        NSURL *url = [NSURL URLWithString:imageURLString];
        SDWebImageManager *manager = [SDWebImageManager sharedManager];
        [manager downloadWithURL:url
                         options:0
                        progress:^(NSInteger receivedSize, NSInteger expectedSize)
         {
             // progression tracking code
         }
                       completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
         {
             if (image)
             {
                 cell.imageView.image = image;
             }
         }];

1 Answers1

0

You should use it this way:

NSString* imageURL = [[tableData objectAtIndex:indexPath.row] valueForKey:@"picture"];
[cell.imageView setImageWithURL:[NSURL URLWithString:imageURL]];

For that, first import the category:

#import <SDWebImage/UIImageView+WebCache.h>

Please note that you don't use the manager at all, you just use the UIImageView+WebCache category provided by the library, which gives you the setImageWithURL: method. There are other variants of the method which allows you to keep track of the download process, a completion handler, etc.

sonxurxo
  • 5,648
  • 2
  • 23
  • 33
  • I have just tried , it works fine but it is loading images when user sees the tableviewcontroller. Actually I want images to be loaded first and then user sees. –  May 19 '14 at 14:55
  • So you should use the manager to download them (it will cache them) before displaying them, but you should never assume that images will be successfully loaded at time – sonxurxo May 19 '14 at 15:26
  • http://stackoverflow.com/questions/23742210/download-data-first-then-show-it-on-tableviewcontroller –  May 19 '14 at 15:58
  • Take a look at my answer here: http://stackoverflow.com/questions/23742210/download-data-first-then-show-it-on-tableviewcontroller/23743395#23743395 – sonxurxo May 19 '14 at 17:06
  • You should either accept the answer if you consider it answered here http://stackoverflow.com/questions/23724551/cache-images-in-tableviewcontroller/23724767#23724767 or remove the question – sonxurxo May 19 '14 at 17:07
  • By the way, do you have any idea about the following question that I have posted , http://stackoverflow.com/questions/23744176/route-tracing-mapkit-in-ios –  May 19 '14 at 17:55