Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 有时SDWebImage中的应用程序崩溃(SDWebImageDownloaderOperation#cancelInternal)_Ios_Objective C_Sdwebimage - Fatal编程技术网

Ios 有时SDWebImage中的应用程序崩溃(SDWebImageDownloaderOperation#cancelInternal)

Ios 有时SDWebImage中的应用程序崩溃(SDWebImageDownloaderOperation#cancelInternal),ios,objective-c,sdwebimage,Ios,Objective C,Sdwebimage,我们已经在应用程序中使用了SDWebImage库。(SDWebImage版本3.7.2) 最近,该应用程序有时会异常终止。(在SDWebImageDownloaderOperation#cancelInternal中) 下面是stacktrace Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0xxx Thread : Crashed: com.apple.main-thread 0 libobjc.A.d

我们已经在应用程序中使用了SDWebImage库。(SDWebImage版本3.7.2) 最近,该应用程序有时会异常终止。(在SDWebImageDownloaderOperation#cancelInternal中)

下面是stacktrace

Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0xxx Thread : Crashed: com.apple.main-thread 0 libobjc.A.dylib 0x180765bd0 objc_msgSend + 16 1 HOGE 0x1002a94d8 -SDWebImageDownloaderOperation cancelInternal 2 HOGE 0x1002a93ec -SDWebImageDownloaderOperation cancel 3 HOGE 0x1002ad63c __69-[SDWebImageManager downloadImageWithURL:options:progress:completed:]_block_invoke131 (SDWebImageManager.m:245) 4 HOGE 0x1002ae0f0 -SDWebImageCombinedOperation cancel 5 HOGE 0x1002b5380 -UIView(WebCacheOperation) sd_cancelImageLoadOperationWithKey: 6 HOGE 0x1002b0c74 -UIButton(WebCache) sd_cancelImageLoadForState: 7 HOGE 0x1002af578 -UIButton(WebCache) sd_setImageWithURL:forState:placeholderImage:options:completed: 8 HOGE 0x1002af3f8 -UIButton(WebCache) sd_setImageWithURL:forState:placeholderImage:options: (称为集合视图单元格的布局子视图)

CollectionView单元格的视图源代码。 标题

MyCollectionViewController

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoCollectionViewCell *cell = (PhotoCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.photo = [_photos objectAtIndex:indexPath.row];
    [cell.imageButton addTarget:self action:@selector(imageButtonPushed:) forControlEvents:UIControlEventTouchUpInside];
    [cell setNeedsLayout];

    // add Load processing
    if (indexPath.row == _photos.count-1 && !_isLast) {
        Photo *photo = [_photos objectAtIndex:indexPath.row];
        [self pagingMyView:photo];
    }

    return cell;
}
为什么非正常终止

我该如何避免这个错误呢

(访问内存是否有问题?)

编辑

谢谢。 它还没有发布,修改代码如下

光收集可视单元(固定)

MyCollectionViewController(固定)


在UITableViewCell和UICollectionViewCell中使用SDWebImageView或SDWebImageButton时,必须注意“单元的重用计时”和“异步下载并设置映像计时”

当您快速滚动时会发生这种情况,因此当异步下载完成时,ui已经被另一个单元格重用

为了避免这个错误(我猜)

在中使用SDWebImage api

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

并用“\uu块”抓住UI的指针


如果您展示更多关于“cellForItemAtIndexPath”的代码,我可以帮助您。

寻求调试帮助的问题(“为什么此代码不起作用?”)必须包括所需的行为、特定问题或错误以及在问题本身中重现该问题所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:如何创建@rmaddy对不起。。谢谢。我现在上传代码。@matt这是访问内存问题吗?换句话说,这是SDWebImage的问题吗?谢谢!我向MyViewController显示有关“cellForItemAtIndexPath”的信息
@implementation PhotoCollectionViewCell

- (void)awakeFromNib
{
    self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.bounds];
    self.selectedBackgroundView.backgroundColor = [BaseColorSet getColor1];

    [_imageButton setBackgroundColor:[BaseColorSet getPhotoBackgroundColor]];
    _imageButton.layer.cornerRadius = 2;
    _imageButton.clipsToBounds = YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];

    NSString *url = [PhotoImgURL get_5:_photo];
    if (!url) {
        url = [NSString stringWithFormat:@"%@/%@/%@",S3_STORAGE_URL,[PhotoDirectory get_5],_photo.filename];
    }

    [_imageButton sd_setImageWithURL:[NSURL URLWithString:url] forState:UIControlStateNormal placeholderImage:nil options:SDWebImageRetryFailed];
    _imageButton.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
    _imageButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
    _imageButton.imageView.contentMode = UIViewContentModeScaleToFill;
}

@end
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoCollectionViewCell *cell = (PhotoCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.photo = [_photos objectAtIndex:indexPath.row];
    [cell.imageButton addTarget:self action:@selector(imageButtonPushed:) forControlEvents:UIControlEventTouchUpInside];
    [cell setNeedsLayout];

    // add Load processing
    if (indexPath.row == _photos.count-1 && !_isLast) {
        Photo *photo = [_photos objectAtIndex:indexPath.row];
        [self pagingMyView:photo];
    }

    return cell;
}
@implementation PhotoCollectionViewCell

- (void)awakeFromNib
{
    self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.bounds];
    self.selectedBackgroundView.backgroundColor = [BaseColorSet getColor1];

    [_imageButton setBackgroundColor:[BaseColorSet getPhotoBackgroundColor]];
    _imageButton.layer.cornerRadius = 2;
    _imageButton.clipsToBounds = YES;
    _imageButton.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
    _imageButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
    _imageButton.imageView.contentMode = UIViewContentModeScaleToFill;
}

-(void)prepareForReuse
{
    [super prepareForReuse];
    [_imageButton sd_cancelImageLoadForState:UIControlStateNormal];
}

@end
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoCollectionViewCell *cell = (PhotoCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.photo = [_photos objectAtIndex:indexPath.row];
    cell.imageButton.tag = cell.photo.photoId;
    NSString *url = [PhotoImgURL get_5:cell.photo];
    if (!url) {
        url = [NSString stringWithFormat:@"%@/%@/%@",S3_STORAGE_URL,[PhotoDirectory get_5],cell.photo.filename];
    }
    [cell.imageButton sd_setImageWithURL:[NSURL URLWithString:url] forState:UIControlStateNormal placeholderImage:nil options:SDWebImageRetryFailed];
    [cell.imageButton addTarget:self action:@selector(imageButtonPushed:) forControlEvents:UIControlEventTouchUpInside];
    [cell setNeedsLayout];

    // add Load processing
    if (indexPath.row == _photos.count-1 && !_isLast) {
        Photo *photo = [_photos objectAtIndex:indexPath.row];
        [self pagingMyView:photo];
    }

    return cell;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath