0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"cell"; 
    TVcell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[TVcell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    cell.titleLabel.text = [[[arrayData objectAtIndex:indexPath.row]valueForKey:@"title"]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 

    cell.txtlabel.text = [[[arrayData objectAtIndex:indexPath.row] valueForKey:@"description"]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
    cell.tag = indexPath.row; 
    cell.imageView.image = nil; 
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); 
    dispatch_async(queue, ^(void) { 

    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[enclosureUrlArray objectAtIndex:indexPath.row]]]; 

    UIImage* image = [[UIImage alloc] initWithData:imageData]; 
    if (image) { 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      if (cell.tag == indexPath.row) { 
       cell.IMGLabel.image = image; 
       [cell setNeedsLayout]; 
       } 
       }); 
      } 
     }); 
     return cell; 

} 

동일한 이미지가 셀에 표시되는 동안 reusing.i 스크롤 뷰 대리자 also.im enclUserArrays에 URL을 저장하고 통과 해요.tabelviewcell에서 비동기 이미지 다운로드 중입니까?

+1

SDWebImage – Paulw11

+0

을 사용해보세요. sdwebimage가 정상적으로 작동하는 라이브러리 클래스가 필요하지 않습니다. 이 솔루션을 원합니다 – karthik

+0

다음 코드를 더 표시하십시오; 위의 코드를 취한 곳에서 전체 기능을 표시합니다. – Paulw11

답변

2

이미지를 다운로드하기 전에 에 cell.IMGLabel.image = nil을 넣으세요.

또는 인터페이스 빌더의 이미지에 사용할 수있는 이미지가없는 이미지를 설정합니다. 따라서 이미지가 다운로드되지 않으면이 장소 소유자 이미지가 표시됩니다. 그렇지 않으면 다운로드 한 이미지가 표시됩니다.

SDWebImage이 경우에 적합합니다. 더 나은 성능을 제공 할 수 있도록 이미지를 캐시합니다. 좋은 제 3 자 라이브러리를 사용하는 데는 아무런 문제가 없습니다. SDWeb 이미지를 사용하여

0

:

#import <SDWebImage/UIImageView+WebCache.h> 

... 

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
             reuseIdentifier:MyIdentifier] autorelease]; 
    } 

    // Here we use the new provided sd_setImageWithURL: method to load the web image 
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] 
         placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 

    cell.textLabel.text = @"My Text"; 
    return cell; 
} 
0

또한

Async image loading from url inside a UITableView cell - image changes to wrong image while scrolling

NSURL *url = [NSURL URLWithString:[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(), ^{ 
       MyCell *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath]; 
       if (updateCell) 
        updateCell.IMGLabel.image = image; 
      }); 
     } 
    } 
}]; 
[task resume]; 

나를 위해 완벽하게 작동이 링크 ..

0

으로 볼뿐만 아니라 NSURLSession을 사용할 수 있습니다 sdwebimage의 도움으로 다음과 같은 이미지를 볼 수 있습니다 : -

NSString *string2 = [[businessListArray objectAtIndex:indexPath.row ]valueForKey:@"logo"]; 
    NSURL *url1 = [NSURL URLWithString: 
        [NSString stringWithFormat: 
        @"%@%@", 
        @"http://dev-demo.info.bh-in-15./upload/post/", 
        string2]]; 

    UIImageView *imageView = (UIImageView *)[cell.contentView viewWithTag:301]; 

    [imageView sd_setImageWithURL:url1 
       placeholderImage:[UIImage imageNamed:@"pocket.png"] 
         completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 
          imageView.image = image; 
         }]; 
관련 문제