我有一個UITableView
,其中使用自動佈局在故事板中定義了自定義UITableViewCell
。該單元有幾個多行UILabels
。UITableView動態單元格高度僅在滾動後纔會更正
UITableView
似乎可以正確計算單元格高度,但對於前幾個單元格,高度在標籤之間沒有正確劃分。 滾動一下後,一切都按預期工作(即使最初不正確的單元格)。
- (void)viewDidLoad {
[super viewDidLoad]
// ...
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"TestCell"];
// ...
// Set label.text for variable length string.
return cell;
}
有什麼我可能會丟失,這是導致汽車佈局不能夠在前幾次完成其工作?
我創建了一個演示此行爲的sample project。
我也面臨這個問題,但下面的答案是不是爲我工作,在此 – 2016-06-28 12:07:55
任何幫助面臨着同樣的問題,增加layoutIfNeeded細胞不起作用我呢?更多的建議 – Max 2016-09-05 13:01:53