添加约束时出错

时间:2015-06-07 04:26:22

标签: ios objective-c autolayout nslayoutconstraint

我有一个静态UITableView,其中UICollectionViewUILabel以编程方式添加constraints。这是代码:

[_labelToChange setTranslatesAutoresizingMaskIntoConstraints:NO];
[_datesCollectionView setTranslatesAutoresizingMaskIntoConstraints:NO];

[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_labelToChange(30)]-0-[_datesCollectionView]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_labelToChange, _datesCollectionView)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[_labelToChange]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_labelToChange)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[_datesCollectionView]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_datesCollectionView)]];

当我这样做时,我收到以下错误:

2015-06-05 12:52:14.102 myApp[2373:44139] 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:0x7fa2e1d80470 V:[DIDatepicker:0x7fa2e1d7fd10]-(0)-|   (Names: '|':UITableViewCellContentView:0x7fa2e1d7f6d0 )>",
    "<NSLayoutConstraint:0x7fa2e1d80510 V:|-(0)-[DIDatepicker:0x7fa2e1d7fd10]   (Names: '|':UITableViewCellContentView:0x7fa2e1d7f6d0 )>",
    "<NSLayoutConstraint:0x7fa2e1da9740 V:|-(0)-[UILabel:0x7fa2e1da8970]   (Names: '|':DIDatepicker:0x7fa2e1d7fd10 )>",
    "<NSLayoutConstraint:0x7fa2e1da9990 V:[UILabel:0x7fa2e1da8970]-(0)-[UICollectionView:0x7fa2e20f8e00]>",
    "<NSLayoutConstraint:0x7fa2e1da9a10 V:[UICollectionView:0x7fa2e20f8e00(85)]>",
    "<NSLayoutConstraint:0x7fa2e1da9a60 V:[UICollectionView:0x7fa2e20f8e00]-(0)-|   (Names: '|':DIDatepicker:0x7fa2e1d7fd10 )>",
    "<NSLayoutConstraint:0x7fa2e1da4a50 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fa2e1d7f6d0(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fa2e1da9990 V:[UILabel:0x7fa2e1da8970]-(0)-[UICollectionView:0x7fa2e20f8e00]>

0 个答案:

没有答案