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は、scrollURLArrayArrayArrayにURLを格納しているスクロールビューのデリゲートも使用しています。tabelviewcellで非同期イメージをダウンロードしていますか?

+1

SDWebImage – Paulw11

+0

を使用しないでください。いいえ、sdwebimageがうまく動作するライブラリクラスは必要ありません。私はこのための解決策を望む – karthik

+0

その後、より多くのコードを表示してください。上記のコードがどこから取られているかを完全な関数で表示してください。 – Paulw11

答えて

2

をダウンロードしてからこのライン以下の画像をダウンロードする前にcellForRowAtIndexPathに入れてください。

また、プレースホルダーの画像(インターフェイスビルダのセルの画像に利用可能な画像がありません)を設定します。画像がダウンロードされないと、このプレースホルダーの画像が表示されます。

SDWebImageこの種のケースには適しています。画像をキャッシュするので、パフォーマンスも向上します。良いサードパーティのライブラリを使用するのは間違いありません。 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]; 
このリンクを参照してください、だけでなくNSURLSessionを使用することができます。..

0

とあなたはこのような画像を表示することができます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; 
         }]; 
関連する問題