【发布时间】:2013-08-19 06:12:40
【问题描述】:
我应该从 URL 加载图像,并使用图像高度设置 tableView 中的行高。为此,我在cellForRowAtIndexPath 中使用了SDWebImage 的类别方法:
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: crashes my app,Nekto 说,当您尝试重新加载某些单元格表时,请检查表视图的大小并看到它已更改,这会导致崩溃
【问题讨论】:
-
错误说明了一切,检查错误前后的行数
-
但是前后没有变化
-
在方法 numberOfrowsinSection 中放一个日志并记录所有情况下的行数
-
我已经这样做了,它没有显示任何变化,我用
reloadData替换了reloadRowsAtIndexpaths,它工作正常
标签: iphone uitableview