Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我开发了一个在 TableView 中显示数据的“今日扩展”。在此表中,使用动态大小自动计算单元格的高度。
然后设置今天扩展的preferredContentSize:
self.preferredContentsize = self.tableView.contentSize
事实是 tableView.contentSize 返回了不正确的值。
我敢肯定,在我的故事板中,我正确设置了约束。
我可以尝试什么?
为 top-bottom-left-right 设置所有 pin 约束。
转到 Storyboard -> 选择 UITableViewCell 然后点击位于Storyboard 右下方的Pin按钮。
选择所有四个销约束,如下图所示,然后单击Add 4 Constraints。
编辑:
您也可以对 xib 文件执行相同的操作。这是自动调整大小的概念。
选择 .xib 文件中的单元格,打开右侧的 Utilities pan,单击“显示尺寸检查器”。
检查下图,您可以看到四个箭头标记为与自动布局相同。通过这样做,您可以实现上述目标。