如何在Xcode中添加此约束?看来我的relatedBy:论证是错误的

编程入门 行业动态 更新时间:2024-10-26 02:31:38
本文介绍了如何在Xcode中添加此约束?看来我的relatedBy:论证是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的代码如下,以及我的应用图片。基本上我想在 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:论证是错误的

本文发布于:2023-10-25 21:47:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528195.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   如何在   Xcode   relatedBy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!