简体   繁体   English

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

[英]UIView height not adjusting to subview heights in UITableView header

I have a UITableView with a header view and a custom row. 我有一个带有标题视图和自定义行的UITableView。 The header view height is not adjusting properly to the constrained heights of its subviews. 标题视图的高度未正确调整为其子视图的约束高度。

The header view container view has the following subviews with constrained heights: 标头视图容器视图具有受高度限制的以下子视图:

  • View (this height should compute to 188 but is 128 instead) 视图(此高度应计算为188,但改为128)
    • Map: UIImage (height = 128) 地图:UIImage(高度= 128)
    • View: UIView (height = 60) 查看:UIView(高度= 60)

在此处输入图片说明

The header view height should be computed at Map Height + View Height = 128 + 60 = 188 as shown in Storyboard. 页眉视图的高度应按照情节提要中所示的“地图高度+视图高度= 128 + 60 = 188”进行计算。 However running this in the simulator squishes the header view to 128 like this: 但是,在模拟器中运行此命令会将标题视图压缩为128,如下所示:

在此处输入图片说明

Further inspection shows the header view height is 128 and not 188 as expected: 进一步检查显示标题视图的高度为128,而不是预期的188:

在此处输入图片说明

Also the Debug area shows a constraint conflict which shows the header view height is trying to be 128 which conflicts with the heights of its subviews. 此外,“调试”区域显示了一个约束冲突,该冲突表明标题视图的高度正试图变为128,这与其子视图的高度冲突。 As a result it squishes the map height: 结果,它压缩了地图高度:

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.

How can I have the header view height properly compute to the heights of its subviews? 如何使标题视图的高度正确计算为其子视图的高度?

In order to force the height of the tableViewHeader I had to manually edit the height property in my Storyboard file with a text editor and this did the trick. 为了强制tableViewHeader的高度,我必须使用文本编辑器在Storyboard文件中手动编辑height属性,这可以解决问题。

在此处输入图片说明

This is most certainly a bug in Xcode 7.1. 这无疑是Xcode 7.1中的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM