0

我应该从 URL 加载图像并将行tableView的高度设置为图像的高度。为此,我使用SDWebImagein的类别方法cellForRowAtIndexPath

NSString *imageURL = [_storeCommodityDetailModel.detailImageURLs objectAtIndex:row];

__weak typeof(UIImageView) *weakImageView = imgViewCell.commodityImageView;
__weak typeof(UIImageView) *weakHoldplaceImageview = imgViewCell.placeholdImageView;
[imgViewCell.placeholdImageView setImage:[UIImage imageFromFile:DEFAULT_IMAGE_REPLACE]];
[imgViewCell.commodityImageView setImageWithURL:[NSURL URLWithString:imageURL] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
    weakImageView.image = image;
    CGFloat section = ((NSIndexPath *)_detailImageHeights[row]).section;
    CGFloat height = ((NSIndexPath *)_detailImageHeights[row]).row;
    if (section == 0) {
        [weakHoldplaceImageview removeFromSuperview];
        if (0 != image.size.width) {

            if (image.size.height < 300) {
                height = 0;
            }else{
                height = weakImageView.width*image.size.height/image.size.width;
            }
            NSIndexPath *index = [NSIndexPath indexPathForRow:height inSection:1];
            [_detailImageHeights replaceObjectAtIndex:row withObject:index];

            [_tableView beginUpdates];
            [_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
            [_tableView endUpdates];;
        }
    }
    weakImageView.height = height;
}];

问题是它总是在以下行崩溃:

[_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]

我不断在以下错误日志中收到错误:

无效更新:第 2 节中的行数无效。更新后现有节中包含的行数 (0) 必须等于更新前该节中包含的行数 (3),加上或减去数字从该部分插入或删除的行数(0 插入,0 删除)加上或减去移入或移出该部分的行数(0 移入,0 移出)。


我找到了原因,您可以看到问题 reloadRowsAtIndexPaths:withRowAnimation: crash my app,Nekto 说当您尝试重新加载某些单元格表时,请检查表视图的大小并看到它已更改,这会导致崩溃

4

1 回答 1

0

您正在更新表格视图的第二部分,将0放入部分

NSIndexPath *index = [NSIndexPath indexPathForRow:height inSection:0];
于 2013-08-20T05:44:16.797 回答