1
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{   static NSString *CellIdentifier = @"cell";

    TVcell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell == nil)
        cell = [[TVcell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

   cell.txtlabel.text = [[[arrayData objectAtIndex:indexPath.row] valueForKey:@"description"]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];


    cell.IMGLabel.contentMode = UIViewContentModeScaleAspectFill;
    cell.IMGLabel.image = nil;

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[enclosureUrlArray objectAtIndex:indexPath.row]]];

    NSURLSessionTask *task = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        if (data) {
            UIImage *image = [UIImage imageWithData:data];
            if (image) {
                dispatch_async(dispatch_get_main_queue(), ^{
                        cell.IMGLabel.image = image;
                          [cell.IMGLabel setImage:image];
                          [cell.IMGLabel.layer setMasksToBounds:YES];
                          [cell.IMGLabel.layer setCornerRadius:2.5f];
                          [cell setNeedsLayout];

                });
            }
        }
    }];
    [task resume];
Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
karthik
  • 159
  • 9
  • 2
    Use SDWebImage library. It is very easy to use and fast. – BalaChandra Jul 06 '16 at 11:36
  • NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval]; – karthik Jul 06 '16 at 13:14
  • here im getting error balachandra – karthik Jul 06 '16 at 13:14

1 Answers1

0

Your problem is that you have no guarantee that your NSUrlRequests will terminate in the same order than they started. This is bad because your cells are re-used for better performance and it can end with strange behavior.

You can find a fix here: Asynchronous downloading of images for UITableView with GCD

Or you can use tools listed here to help you address this issue: https://stackoverflow.com/a/32601838/3769338

Community
  • 1
  • 1
tgyhlsb
  • 1,905
  • 14
  • 21