AFNetworking网络连接丢失错误

时间:2014-10-30 13:59:46

标签: ios uiimageview afnetworking-2

我有UICollectionView,其中每个单元格都有一些数据,如名称,价格和图片。我使用setImageWithURLRequest:placeholderImage:success:failure:中的<UIImageView+AFNetworking.h>方法从http://serveraddress/images/19/918324402131722.jpg等网址下载图片。当我快速滚动时,一切正常。当我滚动得非常快时会出现问题。然后一些(假设有5%的请求)因错误而失败:

Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost."
UserInfo=0x7fafbf64e6c0 {
     NSUnderlyingError=0x7fafbf3d65c0 "The network connection was lost.",
     NSErrorFailingURLStringKey=http://serveraddress/images/19/918324402131722.jpg, 
     NSErrorFailingURLKey=http://serveraddress/images/19/918324402131722.jpg, 
     _kCFStreamErrorDomainKey=1, 
     _kCFStreamErrorCodeKey=54,
     NSLocalizedDescription=The network connection was lost.
}

另请注意,当再次通过在屏幕上移动来重新加载单元格时,一切正常并且图像出现。这是我的代码:

- (ProductCollectionCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

ProductCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ProductCollectionCellIdentifier forIndexPath:indexPath];

Product *product = _model.products[indexPath.row];
[cell.activityIndicator startAnimating];
@weakify(cell);
[cell.imageView setImageWithURLRequest:[product thumbURLRequest] placeholderImage:nil
                               success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
                                   @strongify(cell);
                                   [cell.activityIndicator stopAnimating];
                                   [cell.imageView setImage:image];

                               } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
                                   @strongify(cell);
                                   [cell.activityIndicator stopAnimating];
                                   [cell setFailedPlaceholder];
                               }];
return cell;
}

注意:我红了并尝试了我在SOF上找到的所有可能和合理的解决方案。 我正在使用AFNetworking版本2.4.1。

知道怎么解决吗?可能是服务器故障?

0 个答案:

没有答案