我有一个带有自定义UITableViewCell
的UITableView
,它在storyboard中使用自动布局进行定义。该单元格具有多个多行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;
}
我可能忽略了什么,导致自动布局在前几次无法正常工作吗?
我创建了一个示例项目来演示这种行为。