2017-06-01 6 views
0

URLとAFNetworking 3.0を使用してTableViewCellで非同期モードでimageViewを設定する方法を理解しようとしています。AFNetworking 3.0(非同期)を使用してURLからTableViewセルイメージを設定する

正しく操作する方法がわかりません。この行に正確に:

cell.productImageView.image = image; 

これは機能しません。私はそれを直接属性とすることはできません。

は、ここに私のコードです:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

ProductCell *cell = [tableView dequeueReusableCellWithIdentifier:@"productCell" forIndexPath:indexPath]; 




NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"MY_URL"]]; 


[cell.imageView setImageWithURLRequest:request placeholderImage:nil success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull image) { 



    cell.productImageView.image = image; 



} failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) { 

    NSLog(@"%@",error); 

}]; 





return cell; 

}

+0

あなたのコードで何が問題になっていますか?イメージを取得していない?または、セルの画像ビューに画像を渡すことができませんか? –

+0

'__weak ProductCell * cell = [tableView dequeueReusableCellWithIdentifier:@" productCell "forIndexPath:indexPath];で試してください。 ' –

+0

@Piyush Patelありがとうございました!出来た。 – BSants

答えて

1

はあなたに@Piyushパテルありがとう!!!それは働いて、私はcell's imageViewに画像を読み込むことができます。ここで、私がしたこと:

__weak ProductCell *weakCell = cell;

[cell.imageView setImageWithURLRequest:request placeholderImage:nil success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull image) { weakCell.productImageView.image = image; } failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) { NSLog(@"%@",error); }]; return cell;
関連する問題