1

我对我的分段 tableview 有点绝望。我使用自定义 UITableViewCell 与 4 图像如下图:

我的自定义 UITableViewCell

我尝试通过 SDWebImage 为每个单元格加载图像。

加载过程都在我的自定义 UITableViewCell 中完成 - 而不是在 UITableViewController 中。从cellForRowAtIndexPathi just 调用[cell setup]在当前单元格中执行以下代码:

NSArray *imageViews = [NSArray arrayWithObjects:self.imageView1, self.imageView2, self.imageView3, self.imageView4, nil];

for (int i = 0; i < self.products.count; i++) {

    Product *currentProduct = [self.products objectAtIndex:i];
    UIImageView *currentImageView = [imageViews objectAtIndex:i];

    NSString *thumbURL = [[CommonCode getUnzippedDirectory] stringByAppendingPathComponent:currentProduct.collectionFolderName];
    thumbURL = [thumbURL stringByAppendingPathComponent:thumbFolder];
    thumbURL = [thumbURL stringByAppendingPathComponent:currentProduct.product_photo];

    [currentImageView setContentMode:UIViewContentModeScaleAspectFit];

    [currentImageView setImageWithURL:[NSURL fileURLWithPath:thumbURL]
                   placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
}

图像都存储在文档目录中,并且不大于最大值。500KB。

问题:

我的问题是,当我滚动浏览我的表格视图时,它突然崩溃了,我不知道为什么。为所有异常启用符号断点表明它由于 SDWebImage 中的一行而崩溃。不幸的是,没有调试器输出:(它在分配图像的地方崩溃)

UIImage *image = nil;
if ([imageOrData isKindOfClass:[NSData class]])
{
    image = [[UIImage alloc] initWithData:(NSData *)imageOrData];
}

我也尝试通过dispatch_asnyc类似的结果加载图像。是否可能与并发文件操作有关?

此外,当我快速滚动时,我会收到内存警告,因此我必须清除 SDWebImage 的缓存。同时停在上面提到的 SDWebImage 中的代码行。

我已经在网上搜索了 2 天,但没有找到有用的东西。我很高兴有一些提示可以解决这个问题。如果有人需要其他数据,例如崩溃报告或其他数据,请告诉我,我会尽快提供。

4

1 回答 1

0

我遇到了同样的问题,但我暂时像下面这样解决了,但它会导致内存问题,尤其是在 iPhone 4s 上

NSArray *arrImgs = cellModel.thumbnails_qqnews;
if (arrImgs.count > 0) {
    [self.imgView.subviews enumerateObjectsUsingBlock:^(__kindof UIImageView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj sd_setImageWithURL:[NSURL URLWithString:arrImgs[idx]] placeholderImage:[UIImage imageNamed:@"placeholdImage"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            if (image != nil) {
                obj.image = [UIImage cutImageWithTargetSize:[NEMulTiNewsCell getImgSize] image:image];
            }
        }];
    }];
}

我认为下载多张图片是不合逻辑的,但我认为的方法是下载多张图片然后在一张图片中绘制多张图片然后显示,但它可能会创建大量代码行。

于 2017-04-10T03:33:24.103 回答