【发布时间】:2016-01-14 12:55:30
【问题描述】:
我有一个包含 2 个多行标签和一个 UIImageView 的单元格。单元格具有动态高度,并使用自动布局自动计算。 我的问题是我在 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 单元格取决于图像大小和两个标签,因为它们是多行且没有固定大小
标签: ios objective-c uitableview autolayout