Ios6 iOS 6自动布局约束错误:“0”;有些东西是零;

Ios6 iOS 6自动布局约束错误:“0”;有些东西是零;,ios6,autolayout,nslayoutconstraint,Ios6,Autolayout,Nslayoutconstraint,我试图在iOS 6中使用约束,并希望将一个标签与另一个标签对齐。一个标签和约束是在点击按钮时动态创建的。这是一个非常简单的例子,但我得到一个有线错误,我不知道是什么原因 守则: - (IBAction)addToLog:(UIButton *)sender { UILabel *labelLastTime = [[UILabel alloc]initWithFrame:CGRectMake(20, 359, 92, 42)]; labelLastTime.text = [NSString str

我试图在iOS 6中使用约束,并希望将一个标签与另一个标签对齐。一个标签和约束是在点击按钮时动态创建的。这是一个非常简单的例子,但我得到一个有线错误,我不知道是什么原因

守则:

- (IBAction)addToLog:(UIButton *)sender {
UILabel *labelLastTime = [[UILabel alloc]initWithFrame:CGRectMake(20, 359, 92, 42)];
labelLastTime.text = [NSString stringWithFormat:@"%@kg x %@", self.selectedPickerWeight, self.selectedPickerRepetitions];

labelLastTime.font = [UIFont boldSystemFontOfSize:17.0];
labelLastTime.textAlignment = NSTextAlignmentCenter;
labelLastTime.textColor = [UIColor colorWithRed:133.0/255.0 green:133.0/255.0 blue:133.0/255.0 alpha:1.0];

labelLastTime.backgroundColor = [UIColor colorWithRed:228.0/255.0 green:228.0/255.0 blue:228.0/255.0 alpha:1.0];
labelLastTime.layer.borderColor = [UIColor colorWithRed:185.0/255.0 green:185.0/255.0 blue:185.0/255.0 alpha:1.0].CGColor;
labelLastTime.layer.borderWidth = 1;
labelLastTime.layer.cornerRadius = 5;

[self.view setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview:labelLastTime];


NSLayoutConstraint *cn = [NSLayoutConstraint constraintWithItem:labelLastTime
                                                       attribute:NSLayoutAttributeTop
                                                       relatedBy:NSLayoutRelationEqual
                                                          toItem:self.labelTodayVsLastTime
                                                       attribute:NSLayoutFormatAlignAllBottom
                                                      multiplier:1.0
                                                        constant:5.0];

[self.view addConstraint:cn];
}

错误:

由于未捕获异常“NSInvalidArgumentException”而终止应用程序,原因:“无法在descriptionForLayoutAttribute\u layoutItem\u系数中创建描述。”。有些东西是零

应用约束时会发生错误,而不是设置约束时。我刚才设置了一个断点

[self.view addConstraint:cn]
当我检查结果时,我得到这个4的零值

container, markerAndPositiveExtraVar, negativeExtraVar and _flange
我遇到了与约束定义稍有不同的问题,原因是Xcode自动完成出现了故障

查看第二个
属性:
行。您可能需要类似于
属性:nslayouttributebottom
的内容


NSLayoutFormatAlignAllBottom
用于构建一个
NSLayoutFormatOptions
位掩码,该位掩码将被赋予
constraintsWithVisualFormat:options:metrics:views:

是否检查以确保self.LabelTodaySlasTime有效?我认为第二个属性是系数?谢谢,我不久前解决了它,但这是正确的答案:)
NSLayoutConstraint *cn = [NSLayoutConstraint constraintWithItem:labelLastTime
  attribute:NSLayoutAttributeTop
  relatedBy:NSLayoutRelationEqual
  toItem:self.labelTodayVsLastTime
  attribute:NSLayoutFormatAlignAllBottom
  multiplier:1.0
  constant:5.0];