gpt4 book ai didi

ios - UITableViewAutomaticDimension 在 iOS 9 中无法正常工作

转载 作者:可可西里 更新时间:2023-11-01 03:57:54 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个固定比例 (16x9) 的自定义 tableViewCells。为此,我在单元格中放置了一个 View ,将其固定到其父 View (尽管我是在界面构建器中完成的:V/H:|-[innerView]-|)。另外,我对其施加了比率约束。

在我的 tableViewController 中,我使用 UITableViewAutomaticDimension 作为表格单元格的高度。

估计行高为 180,这是单元格在 320 像素宽显示器上的确切大小(正如我所看到的那样)。

我仍在针对 8.4 进行部署,但在装有 iOS 9 的设备上运行项目时,我收到大量自动布局警告,尽管一切正常且看起来很完美。

警告本身是绝对正确的。有两个我不想要的限制 – 这些是 iOS 自己添加的。

2015-09-29 11:24:57.771 app[1039:324736] 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)
(
"<NSLayoutConstraint:0x147d3e0d0 UIView:0x14901ff70.height == 0.5625*UIView:0x14901ff70.width>",
"<NSLayoutConstraint:0x147dd0210 H:|-(0)-[UIView:0x14901ff70] (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x147deeca0 V:|-(0)-[UIView:0x14901ff70] (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x149053c30 V:[UIView:0x14901ff70]-(0)-| (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x147dbc2b0 H:[UIView:0x14901ff70]-(0)-| (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x149070800 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x14901f960(179.5)]>",
"<NSLayoutConstraint:0x1490707b0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14901f960(320)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x147d3e0d0 UIView:0x14901ff70.height == 0.5625*UIView:0x14901ff70.width>

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.

我在这里唯一看到的是 iOS 神奇地减去了缺失的 0.5 像素。

最佳答案

问题是 tableview 自动添加的两个约束。 UIView-Encapsulated-Layout-Height and width 大概是table view 在初始加载时根据cell 的约束计算出来的高度和宽度。

"<NSLayoutConstraint:0x149070800 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x14901f960(179.5)]>",
"<NSLayoutConstraint:0x1490707b0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14901f960(320)]>"

由于这些约束的优先级是 1000,您可以做的是降低高度和宽度约束的优先级,并在需要时(加载时)应用封装的尺寸。

关于ios - UITableViewAutomaticDimension 在 iOS 9 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32692544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com