最佳答案
我有一个使用自动布局在故事板中定义的自定义 UITableViewCell
的 UITableView
。该细胞有几个多行 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;
}
有没有什么我可能错过了,这是导致自动布局不能做它的工作的头几次?
我创建了一个 样本项目来演示这种行为。