Search code examples
iosobjective-cxcodeuitableviewnsurl

How to show URL Images in TableView cell without stuck?


I have showed collections of URLImage in tableview cell. It is stuck while I am scrolling the cell. I have used third parties like SDWebImageManager and AFNetWorking. Never the less the cell has been stuck.

[imageVw setImageWithURL:[NSURL URLWithString:self.imgaeRecord.PreviewURl]placeholderImage:[UIImage imageNamed:@"default-thumbnail.jpg"]];

OR

NSURL *url =[NSURL URLWithString:[self.MoviesListImage objectAtIndex:indexPath.row]];

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:url
                      options:0
                     progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                        // progression tracking code
                     }
                    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                    if (image) {
                        cell.recipeImageView.image = image;
                    }
                }];

Solution

  • In your cellForRowAtIndexPath

    NSURL *url =[NSURL URLWithString:[self.MoviesListImage objectAtIndex:indexPath.row]];
    
    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    [manager downloadImageWithURL:url
                      options:0
                     progress:^(NSInteger receivedSize, NSInteger  expectedSize) {
                        // progression tracking code
               }
                    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                    if (image) {
                       dispatch_async(dispatch_get_main_queue(), ^{
                       TableViewCellClass *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath];
                       if (updateCell)
                         updateCell.yourImageView.image = image;
                   });
               }
           }
    }];
    [task resume];