0
我有一个单元格,其中包含2个多行标签和一个UIImageView。单元具有动态高度,并使用Autolay自动计算。 我的问题是,我在cellForRowAtIndexPath中下载图像:直到那时我不知道图像的高度。在开始的单元格没有正确的布局,我不得不滚动到其他单元格,当我回到我的单元格(它重新绘制),然后布局是正确的。图像下载时如何重新绘制单元格? 下面是我正在使用的代码:表格单元格内的图像块和更改自动布局
NSString static * cellIdentifier = @"titlePostCell";
PostTitleTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[PostTitleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.titleLabel.text = self.entry.title;
cell.descriptionLabel.text = self.entry.entry_description[@"value"];
[cell setNeedsUpdateConstraints];
[cell.postImageView pin_setImageFromURL:[[CTImageHelper sharedInstance] resizedImageURLConverterFromStringWithPrefix:self.entry.card_image] completion:^(PINRemoteImageManagerResult *result) {
cell.heightSize = [NSNumber numberWithInt:result.image.size.height/2];
cell.heightImageConstraint.constant = cell.heightSize.floatValue;
}];
return cell;
谢谢!
您需要使单元格自动布局,使单元格的高度应该具有uiimageview高度的相关性。我不认为在块内的cellForRowIndex中给出约束是好方法。 – nikhil84
@ nikhil84单元取决于图像大小和两个标签,因为它们是多行,并且它们没有固定大小 –