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;
}
あなたのコードで何が問題になっていますか?イメージを取得していない?または、セルの画像ビューに画像を渡すことができませんか? –
'__weak ProductCell * cell = [tableView dequeueReusableCellWithIdentifier:@" productCell "forIndexPath:indexPath];で試してください。 ' –
@Piyush Patelありがとうございました!出来た。 – BSants