为了账号安全,请及时绑定邮箱和手机立即绑定

Unable to simultaneously satisfy constraints.错误处理

标签:
Html5

在项目中使用了autoLayout来对自定义的cell进行约束。cell可以正常显示, 看是控制台打印了如下报错信息:
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.
( "<NSLayoutConstraint:0x7fbb85999770 V:[UIView:0x7fbb85e8f850(1)]>", "<NSLayoutConstraint:0x7fbb85e24e80 V:[UIView:0x7fbb85e8f570(1)]>", "<NSLayoutConstraint:0x7fbb85e6f500 V:[UIImageView:0x7fbb85e79b80(200)]>", "<NSLayoutConstraint:0x7fbb83758b80 V:[UIView:0x7fbb85da7610(44)]>", "<NSLayoutConstraint:0x7fbb8375a240 V:|-(0)-[UIView:0x7fbb85e8f850] (Names: '|':UIView:0x7fbb85e78d40 )>", "<NSLayoutConstraint:0x7fbb8375a330 V:[UIView:0x7fbb85e8f850]-(20)-[UILabel:0x7fbb85e7e8a0'\U5c0f\U5446\U74dc\U6eda\U5440\U6eda']>", "<NSLayoutConstraint:0x7fbb8375a470 V:[UILabel:0x7fbb85e7e8a0'\U5c0f\U5446\U74dc\U6eda\U5440\U6eda']-(5)-[UILabel:0x7fbb8599abf0'\U6765\U81ea \U5c0f\U7ec4[\U60a6\U53cb\U4f1a]']>", "<NSLayoutConstraint:0x7fbb8375a510 V:[UILabel:0x7fbb8599abf0'\U6765\U81ea \U5c0f\U7ec4[\U60a6\U53cb\U4f1a]']-(12)-[UILabel:0x7fbb85e807d0'\U7f8e\U56fd\Uff0c\U6cd5\U56fd\U548c\U4e2d\U56fd\U5973\U4eba\U8981\U51cf\U80a5\U7684\U65f6\U5019']>", "<NSLayoutConstraint:0x7fbb8375a650 V:[UILabel:0x7fbb85e807d0'\U7f8e\U56fd\Uff0c\U6cd5\U56fd\U548c\U4e2d\U56fd\U5973\U4eba\U8981\U51cf\U80a5\U7684\U65f6\U5019']-(12)-[UIView:0x7fbb85e8f570]>", "<NSLayoutConstraint:0x7fbb8375a740 V:[UIView:0x7fbb85e8f570]-(12)-[UILabel:0x7fbb85e7fba0'\U7f8e\U56fd']>", "<NSLayoutConstraint:0x7fbb8375a790 V:[UILabel:0x7fbb85e7fba0'\U7f8e\U56fd']-(12)-[UIImageView:0x7fbb85e79b80]>", "<NSLayoutConstraint:0x7fbb8375a880 V:[UIImageView:0x7fbb85e79b80]-(3)-[UILabel:0x7fbb85e90010]>", "<NSLayoutConstraint:0x7fbb8375a8d0 V:[UILabel:0x7fbb85e90010]-(0)-[UIView:0x7fbb85da7610]>", "<NSLayoutConstraint:0x7fbb8375a920 V:[UIView:0x7fbb85da7610]-(0)-| (Names: '|':UIView:0x7fbb85e78d40 )>", "<NSLayoutConstraint:0x7fbb8375b0d0 V:|-(0)-[UIView:0x7fbb85e78d40] (Names: '|':UITableViewCellContentView:0x7fbb859a4e90 )>", "<NSLayoutConstraint:0x7fbb8375b170 UITableViewCellContentView:0x7fbb859a4e90.bottomMargin == UIView:0x7fbb85e78d40.bottom - 8>", "<NSLayoutConstraint:0x7fbb85a75650 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fbb859a4e90(297.5)]>"`` )

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fbb85e6f500 V:[UIImageView:0x7fbb85e79b80(200)]>

看到开头的报错信息, 是说不能同时满足我的约束条件,让我从下面列出的的约束条件中找出我不想要的,然后修复它。 于是我就挨个检查了每个约束条件, 去掉了不必要的约束条件, 但仍是一直报错。 最后发现了这句话:
Will attempt to recover by breaking constraint 这句话是说尝试打破下面的约束来进行修复, 这才找到问题所在。 对于这个这个UIImageView 我在cell中约束的值的高度是100,但是在实际的使用中,它的实际值却是200 ,所以会有约束冲突报错。
解决的办法就是降低这个约束的优先级(Priority),当系统实际计算 的高度与我设置的约束值不一样时, 取系统的值, 就不会再报错了。
修改方式如下:
选中要修改的约束,将其值调低(999)即可。

QQ20160701-0.png



作者:墨守青城
链接:https://www.jianshu.com/p/737bf71c4dd9


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消