我有一个使用自动布局在故事板中定义UITableView的自UITableViewCell定义.细胞有几条多线UILabels.
在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;
}
Run Code Online (Sandbox Code Playgroud)
有什么我可能会遗漏,导致自动布局在前几次无法完成其工作吗?
我已经创建了一个演示此行为的示例项目.
