I am trying to figure out how can I set an imageView in my TableViewCell using URL and AFNetworking 3.0 in asynchronous mode.
I don´t know how to work with it properly. Exactly in this line:
cell.productImageView.image = image;
It doesn´t work. I cannot attribute it directly, right?
Here is my code:
-(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;
}
Thank you @Piyush Patel !!! It worked, I could load the image on cell´s imageView. Here, what I did:
__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;