UIView 高度未调整为 UITableView 中的子视图高度 header

UIView height not adjusting to subview heights in UITableView header

我有一个带有 header 视图和自定义行的 UITableView。 header 视图高度未正确调整到其子视图的约束高度。

header 视图容器视图具有以下高度受限的子视图:

header 视图高度应按地图高度 + 视图高度 = 128 + 60 = 188 计算,如情节提要中所示。但是 运行 模拟器中的这个将 header 视图压缩到 128,如下所示:

进一步检查显示 header 视图高度为 128 而不是预期的 188:

调试区域也显示约束冲突,显示 header 视图高度试图为 128,这与其子视图的高度冲突。结果它压缩了地图高度:

2015-11-27 16:58:46.415 MyApp[3387:52799] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x7fcb5acf1270 h=--& v=--& V:[UIView:0x7fcb5c246620(128)]>",
    "<NSLayoutConstraint:0x7fcb5c24c440 V:[Stop Details Container]-(0)-|   (Names: Stop Details Container:0x7fcb5c24c490, '|':UIView:0x7fcb5c246620 )>",
    "<NSLayoutConstraint:0x7fcb5c24c6f0 V:[Map]-(0)-[Stop Details Container]   (Names: Stop Details Container:0x7fcb5c24c490, Map:0x7fcb5c24aa10 )>",
    "<NSLayoutConstraint:0x7fcb5c24c830 V:|-(0)-[Map]   (Names: Map:0x7fcb5c24aa10, '|':UIView:0x7fcb5c246620 )>",
    "<NSLayoutConstraint:0x7fcb5c24c880 V:[Map(128)]   (Names: Map:0x7fcb5c24aa10 )>",
    "<NSLayoutConstraint:0x7fcb5c24c8d0 V:[Stop Details Container(60)]   (Names: Stop Details Container:0x7fcb5c24c490 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fcb5c24c880 V:[Map(128)]   (Names: Map:0x7fcb5c24aa10 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

如何让 header 视图高度正确计算为其子视图的高度?

为了强制设置 tableViewHeader 的高度,我不得不使用文本编辑器在情节提要文件中手动编辑高度 属性,这成功了。

这肯定是 Xcode 7.1 中的错误。