最佳答案
在 iOS8中,您可以通过简单地设置估计的行高来获得100% 的动态表格视图单元格,然后使用 Auto Layout 在单元格中布局您的元素。如果内容的高度增加,单元格的高度也会增加。这是非常有用的,我想知道是否同样的壮举可以完成表视图中的节标题?
例如,是否可以在 tableView:viewForHeaderInSection:
中创建一个 UIView
,添加一个 UILabel
子视图,针对视图为标签指定自动布局约束,并使视图的高度增加以适应标签的内容,而不必实现 tableView:heightForHeaderInSection:
?
viewForHeaderInSection
的文档声明: “此方法只有在 tableView: heightForHeaderInSection: 也实现时才能正常工作。”我还没听说 iOS8有什么变化。
如果一个人不能做到这一点,那么模仿这种行为的最佳方式是什么?