以编程方式尝试NSLayoutContraint给出“无法同时满足约束”。

时间:2013-04-05 00:29:03

标签: ios ios6 autolayout

我似乎遇到了一些问题,以编程方式为我正在使用的UITableView设置我的约束。我的尝试如下,并尝试了使用translatesAutoresizingMaskIntoConstraints的所有组合。

    self.view.translatesAutoresizingMaskIntoConstraints = NO;
    _tableView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-100-[_tableView]-20-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView)]];

我只是想在UIViewController上的UITableView的开头和底部添加一个空格。任何人都可以帮忙吗?

长而长的错误如下。

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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x75c8500 h=-&- v=-&- UITableView:0x799e400.midY == UIView:0x71a4ec0.midY>",
    "<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-|   (Names: '|':UIView:0x71a4ec0 )>",
    "<NSLayoutConstraint:0x71a5a60 V:|-(100)-[UITableView:0x799e400]   (Names: '|':UIView:0x71a4ec0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-|   (Names: '|':UIView:0x71a4ec0 )>

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-04-04 20:06:57.648 New eCard[29731:c07] 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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x75c8540 h=-&- v=-&- UITableView:0x799e400.height == UIView:0x71a4ec0.height>",
    "<NSAutoresizingMaskLayoutConstraint:0x75c8500 h=-&- v=-&- UITableView:0x799e400.midY == UIView:0x71a4ec0.midY>",
    "<NSLayoutConstraint:0x71a5a60 V:|-(100)-[UITableView:0x799e400]   (Names: '|':UIView:0x71a4ec0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x71a5a60 V:|-(100)-[UITableView:0x799e400]   (Names: '|':UIView:0x71a4ec0 )>

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.
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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x75c8540 h=-&- v=-&- UITableView:0x799e400.height == UIView:0x71a4ec0.height>",
    "<NSAutoresizingMaskLayoutConstraint:0x75c8500 h=-&- v=-&- UITableView:0x799e400.midY == UIView:0x71a4ec0.midY>",
    "<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-|   (Names: '|':UIView:0x71a4ec0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-|   (Names: '|':UIView:0x71a4ec0 )>

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.

1 个答案:

答案 0 :(得分:-2)

我发现了关于UICollectionView的这个问题。我想这是开始调试的一个好点。

UICollectionView Cell + UiLabel with AutoLayout

我试过的一些其他解决方案没有成功: https://blog.safaribooksonline.com/2012/10/27/tip-unsatisfiable-auto-layouts-in-ios-6/ UITableView with autolayout and offset constraints