简体   繁体   中英

download image from URL string using UIImageView+AFNetworking.h

I have problem with download image from URL string. When I use this for download image and set in on imageView on view it works but now I have to set it on imageView on Cell. I cannot put this on cellForRowAtIndexPath: method where I have access to imageView on cell.

__weak EditViewController *weakSelf = self;

    [weakSelf.imageView setImageWithURLRequest:request placeholderImage:placeholderImage
                                           success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {

                                               weakSelf.imageView.image = image;
                                               [self.tableView reloadData];

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

                                               [self prepareAndShowAlertView];
    }];

I'll be glad for any help with this. Thanks in advance.

If you are not able to put your download to cellForRow:AtIndexPath: delegate method than you need to add @property (nonatomic, strong) UIImage *image; to your controller and when image is downloaded

    ...success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {

    weakSelf.imageView.image = image;
    self.image = image;
    [self.tableView reloadData];

}

and in cellForRow:AtIndexPath: setup your image

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    [cell.imageView setImage:self.image];
    return cell;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM