我以编程方式使用自动布局约束来布局我的自定义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)]>"
and I cannot set the translatesAutoresizingMaskIntoConstraints
property of the contentView
to NO => it would mess up the entire cell.
44是默认的单元格高度,但是我在表视图委托中定义了我的自定义高度,那么为什么单元格contentView有这个约束呢?是什么导致了这一切?
在iOS6中,它不会发生,在iOS6和iOS7上,一切看起来都很好.
我的代码很大,所以我不会把它贴在这里,但如果你需要的话,可以随意索要一个粘贴箱.
要指定我是如何做到这一点的,请参见单元初始化:
- 我创建我所有的标签、按钮等
- 我将他们的
translatesAutoresizingMaskIntoConstraints
属性设置为NO - 我将它们添加为单元格
contentView
的子视图 - 我在
contentView
号车上添加了限制条件
我也非常想了解为什么这种情况只发生在iOS7上.