我有一个包含 tableView
的 cell
。我需要这个 tableView
来实现 datePicker
扩展行为,如下所示:
但我有这个:
我的代码非常简单。在这两个 tableView
中,我都将 estimatedRowHeight
和 rowHeight
设置为 UITableViewAutomaticDimension
(在这种情况下,我得到了第二个 gif 显示的结果。通过手动将 heightForRowAtIndexPath
设置为特定高度值实现的预期结果(第一个 git)。但是我得到了我没有预料到的结果。
此外,当我运行该应用程序时,我会收到以下警告:
[Warning] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.
为什么会这样?并且可以通过不添加新的开销代码来完成这项工作(例如,我相信如果我使用 intrinsic size
做一些魔术,UITableViewAutomaticDimension
将正确工作)。
附言这是 the demo project .
最佳答案
如果您正在使用 UITableViewAutomaticDimension
,您需要设置单元格中所有元素的约束,从上、左、下、右。如果您不这样做,那么您将收到问题中显示的警告。
关于ios - UITableViewAutomaticDimension 不适用于包含 tableView 的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40693246/