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單元取決於圖像大小和兩個標籤,因爲它們是多行,並且它們沒有固定大小 –