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;
}
你的代碼有什麼問題?沒有獲取圖像?或無法在單元格的imageview上傳遞圖像? –
用'__weak ProductCell * cell = [tableView dequeueReusableCellWithIdentifier:@「productCell」forIndexPath:indexPath]; ' –
@Piyush Patel謝謝!有效。 – BSants