我有一个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