尝试加载xib文件时无法同时满足约束

时间:2016-12-14 11:50:53

标签: ios iphone swift2 autolayout ios9.3

我正在尝试使用xib文件实现UITableView 但是当我运行应用程序时,我收到以下错误& xib适合像iPhone4s一样小屏幕 它在更大的显示尺寸下工作正常。

Screenshot of xib

任何帮助将不胜感激

错误

    2016-12-14 17:12:41.826 FoodStrock[5776:1761262] 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:0x7fcc2a6dfac0 V:[UIImageView:0x7fcc2a6e1010(63)]>",
    "<NSLayoutConstraint:0x7fcc2a617530 V:[UIImageView:0x7fcc2a6e1010]-(8)-|   (Names: '|':UITableViewCellContentView:0x7fcc2a6e1270 )>",
    "<NSLayoutConstraint:0x7fcc2a6cc3b0 V:|-(9)-[UIImageView:0x7fcc2a6e1010]   (Names: '|':UITableViewCellContentView:0x7fcc2a6e1270 )>",
    "<NSLayoutConstraint:0x7fcc2a4955a0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fcc2a6e1270(59.6667)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fcc2a6dfac0 V:[UIImageView:0x7fcc2a6e1010(63)]>

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.
2016-12-14 17:12:41.827 FoodStrock[5776:1761262] 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:0x7fcc2a6a69d0 V:[UILabel:0x7fcc2a6e1670'Address'(63)]>",
    "<NSLayoutConstraint:0x7fcc2a693820 UILabel:0x7fcc2a6e1670'Address'.bottom == UITableViewCellContentView:0x7fcc2a6e1270.bottomMargin>",
    "<NSLayoutConstraint:0x7fcc2a6e0c00 UILabel:0x7fcc2a6e1670'Address'.top == UITableViewCellContentView:0x7fcc2a6e1270.topMargin + 1>",
    "<NSLayoutConstraint:0x7fcc2a4955a0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fcc2a6e1270(59.6667)]>"
)

1 个答案:

答案 0 :(得分:0)

将UIImageView,UILabel,UIButton放在单个UIView中(说mainView)。现在,mainView约束将是xib视图(superView)的前导,尾随,顶部底部。现在UIImageView,UILabel,UIButton的约束是根据你的要求w.r.t. MAINVIEW。

注意:尽可能减少对UIComponent的限制,但请注意它完全满足您的要求。像这里一样,给出这样的约束:

  1. UIImage:顶部,底部,引导wrt mainView和恒定宽度,或者您可以水平居中给容器,前导,高度,宽度。

  2. UIButton:顶部,底部,尾随wrt mainView和恒定宽度,或者您可以水平居中给容器,前导,高度,宽度。

  3. UILabel:领先的尾随和水平居中的容器就够了,但你也可以给出高度。 UILabel可以根据您需要指定x和y坐标的文本字体大小自动获取高度和宽度。

相关问题