我的代码如下,以及我的应用图片。基本上我想在 viewDidLoad 方法中为此视图控制器添加一个约束,以对齐两个标签,使它们从相同的x位置开始。无论出于何种原因,我都会收到此警告:
My code is below, as well as the image of my app. Basically I want to add a constraint in the viewDidLoad method for this view controller to align the two labels so they start at the same x position. For whatever reason, I'm getting this warning, though:
指向整数转换的不兼容指针将'UIView *'发送到类型'的参数NSLayoutRelation'(又名'enum NSLayoutRelation');
Incompatible pointer to integer conversion sending 'UIView *' to parameter of type 'NSLayoutRelation' (aka 'enum NSLayoutRelation');
当我运行应用程序时,我收到以下错误:
And when I run the app I get the following error:
*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'* + [NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]:未知布局属性'
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: Unknown layout attribute'
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self.carMakeLabel attribute:NSLayoutRelationEqual relatedBy:self.view toItem:self.carModelLabel attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0]; [self.view addConstraint:constraint];
推荐答案
尝试:
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self.carMakeLabel attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.carModelLabel attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0]; [self.view addConstraint:constraint];确保self.carModelLabel和self.carMakeLabel都在self.view的视图层次结构中。
Make sure self.carModelLabel and self.carMakeLabel are both in the view hierarchy of self.view.
更多推荐
如何在Xcode中添加此约束?看来我的relatedBy:论证是错误的
发布评论