我用编程方式使用自动布局约束来布局我自定义的 UITableView 单元格,并且在 tableView:heightForRowAtIndexPath:
中正确定义了单元格大小
它在 iOS6上运行良好,在 iOS7上也能运行 听着
但是当我在 iOS7上运行这个应用程序时,我在控制台上看到了这样的信息:
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2013-10-02 09:56:44.847 Vente-Exclusive[76306:a0b] 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:0xac4c5f0 V:|-(15)-[UIImageView:0xac47f50] (Names: '|':UITableViewCellContentView:0xd93e850 )>",
"<NSLayoutConstraint:0xac43620 V:[UIImageView:0xac47f50(62)]>",
"<NSLayoutConstraint:0xac43650 V:[UIImageView:0xac47f50]-(>=0)-[UIView:0xac4d0f0]>",
"<NSLayoutConstraint:0xac43680 V:[UIView:0xac4d0f0(1)]>",
"<NSLayoutConstraint:0xac436b0 V:[UIView:0xac4d0f0]-(0)-| (Names: '|':UITableViewCellContentView:0xd93e850 )>",
"<NSAutoresizingMaskLayoutConstraint:0xac6b120 h=--& v=--& V:[UITableViewCellContentView:0xd93e850(44)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xac43650 V:[UIImageView:0xac47f50]-(>=0)-[UIView:0xac4d0f0]>
的确在这个列表中有一个我不想要的约束:
"<NSAutoresizingMaskLayoutConstraint:0xac6b120 h=--& v=--& V:[UITableViewCellContentView:0xd93e850(44)]>"
我不能将 contentView
的 translatesAutoresizingMaskIntoConstraints
属性设置为 NO = > ,否则会搞乱整个单元格。
44是默认的单元格高度,但是我在表视图委托中定义了自定义高度,那么为什么单元格 contentView 有这个约束呢?是什么引起的?
在 iOS6中,这种情况并没有发生,在 iOS6和 iOS7中,一切看起来都很正常。
我的代码相当大,所以我不会张贴在这里,但随时要求粘贴剂,如果你需要它。
为了说明我是如何做到的,在单元格初始化方面:
translatesAutoresizingMaskIntoConstraints
属性设置为 NOcontentView
的子视图contentView
上添加了约束我也非常想知道为什么只有在 iOS7上才会出现这种情况。