gpt4 book ai didi

ios - 在不知道高度的情况下在单元格内异步下载图像

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:37:05 24 4
gpt4 key购买 nike

我正面临这个问题,我一直在尝试找出解决方法,但没有成功。我有一个表格 View ,其中包含一个图像的单元格,我仍然不知道它的高度是多少。我为 imageView 的高度约束创建了一个导出,我正在使用 PinRemoteImage 异步下载图像(我也可以使用 SDWebImage 但我认为它在 iOS 9 中有问题)。在 block 内部是我为高度约束分配新常量的地方,然后我进行布局更新。单元格永远不会更新,我能正确看到图像的唯一方法是向下滚动然后向上滚动(当 tableview 重新绘制单元格时)

__weak typeof(UITableView*) weakTable = tableView;
__weak typeof(NSIndexPath*) index = indexPath;

[cell.commentImageView pin_setImageFromURL:[[CTImageHelper sharedInstance] resizedImageURLConverterFromStringWithPrefix:comment.image.completePath andOptions:optionsString] completion:^(PINRemoteImageManagerResult *result) {
CommentTableViewCell *cellToUpdate = [weakTable cellForRowAtIndexPath:index];
cellToUpdate.heightSize = [NSNumber numberWithFloat:result.image.size.height/2];
cellToUpdate.commentImageViewHeightConstraint.constant = result.image.size.height/2;
[cellToUpdate setNeedsLayout];
}];

这是自动设置表格 View 行高的代码

self.postTableView.estimatedRowHeight = 244.0;
self.postTableView.rowHeight = UITableViewAutomaticDimension;

还有一张关于单元格约束的图片: enter image description here

关于我做错了什么的任何想法?谢谢!

最佳答案

layoutIfNeeded 放在 setNeedsLayout 之后

 [cellToUpdate setNeedsLayout];
[cellToUpdate layoutIfNeeded];

// and then tell the tableView to update.
[weakTable beginUpdates];
[weakTable endUpdates];
// then scroll to the current indexPath
[weakTable scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionNone
animated:NO];

更新 [weakTable beginUpdates];[weakTable endUpdates]; 如果一次多次调用它可能会崩溃。您需要确保它们之间没有冲突。

您也可以尝试重新加载单元格本身。

 [cellToUpdate setNeedsLayout];
[cellToUpdate layoutIfNeeded];
[weakTable reloadRowsAtIndexPaths:[indexPath] withRowAnimation:UITableViewRowAnimationNone];

关于ios - 在不知道高度的情况下在单元格内异步下载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35018629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com