【发布时间】:2014-01-13 18:54:45
【问题描述】:
我正在以编程方式使用自动布局约束,并且在我的应用程序中经常看到相同类型的错误,通常与如下所示的约束有关:
"<NSAutoresizingMaskLayoutConstraint:0x82da910 h=--& v=--& V:[UITableViewCellContentView:0x82d9fb0(99)]>"
我已经在https://github.com/nicolasccit/AutoLayoutCellWarning放了一些示例代码来重现
在这个示例中,我创建了一个非常简单的视图,其中包含 2 个 UI 元素:一个名为 imageThumbnail 的图像视图和一个名为 labelName 的标签,带有一些约束:
"H:|-padding-[_imageThumbnail(==imageWidth)]-[_labelName]";
"V:|-padding-[_imageThumbnail(==imageHeight)]-padding-|";
"V:|-padding-[_labelName]";
在这两个元素上,我将 AutoresizingMaskIntoConstraints 设置为 NO。
我得到以下异常:
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:0xa6e4f90 V:[UIImageView:0xa6e4340]-(10)-| (Names: '|':UITableViewCellContentView:0xa6e4150 )>",
"<NSLayoutConstraint:0xa6e4f10 V:[UIImageView:0xa6e4340(80)]>",
"<NSLayoutConstraint:0xa6e4ed0 V:|-(10)-[UIImageView:0xa6e4340] (Names: '|':UITableViewCellContentView:0xa6e4150 )>",
"<NSAutoresizingMaskLayoutConstraint:0xa6e4ac0 h=--& v=--& V:[UITableViewCellContentView:0xa6e4150(99)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xa6e4f90 V:[UIImageView:0xa6e4340]-(10)-| (Names: '|':UITableViewCellContentView:0xa6e4150 )>
我知道最后一个约束与内容视图有关,但我不清楚要正确删除它(设置
在 contentView 上将 AutoresizingMaskIntoConstraints 设置为 NO 会引发错误,并且在下面的 SO 链接中,它会弄乱整个布局):
<NSAutoresizingMaskLayoutConstraint:0xa6e4ac0 h=--& v=--& V:[UITableViewCellContentView:0xa6e4150(99)]>
我在Auto layout constraints issue on iOS7 in UITableViewCell 看到了答案,但似乎没有一个对我有用。
我相信我定义的约束是有效且非常简单的,但似乎无法弄清楚发生了什么。而且我看到在 iOS 6.1 和 iOS 7 中都出现了异常。
知道我在这里做错了什么吗?
谢谢, 尼古拉斯
【问题讨论】:
标签: ios objective-c uitableview autolayout