簡體   English   中英

使用AFNetworking 3.0(異步)從URL設置TableView單元格圖像

[英]Set TableView Cell image from URL using AFNetworking 3.0 (asynchronous)

我試圖弄清楚如何在異步模式下使用URL和AFNetworking 3.0在TableViewCell中設置imageView。

我不知道如何正確使用它。 恰好在這一行:

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;

}

謝謝@Piyush Patel !!! 它起作用了,我可以將圖像加載到單元格的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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM