UIImageView+Afnetworking 不能正常工作

UIImageView+Afnetworking doesn't Work Properly

我已经从 here 复制了文件的内容并创建了一个 UIImageView+AFNetworking.h 并导入了我的实现文件

现在,当我编写以下代码时出现此错误,但是当我删除代码块时,一切正常。

我想在自定义 table cell.The url 中显示我正在抓取的图像 JSON

NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[dictArray objectForKey:@"image"]]];
[cell.thumbnailImageView setImageWithURLRequest:imageRequest placeholderImage:nil
                               success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){
                                   NSLog(@"success");
                                   cell.thumbnailImageView.image = image;
                                   cell.thumbnailImageView.contentMode = UIViewContentModeScaleAspectFit;
                                   cell.thumbnailImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
                                   [cell setNeedsLayout];// To update the cell {if not using this, your image is not showing over cell.}
                               }failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
                                   NSLog(@"Failure");}];

这是错误的屏幕截图

加载后崩溃

除了使用 afnetworking 你可以只使用 dispatch 方法

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
      NSString *url = [indexDic objectForKey:@"image"];
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
    UIImage *image = [UIImage imageWithData:imageData];
    dispatch_async(dispatch_get_main_queue(), ^{

        cellImg.image = image;

    });
});

return cell;

 }