Swift:如何检查哪个视图引起约束错误

问题描述 投票:1回答:1

尝试加载VC时出现以下错误:

Thread 1: Exception: "Unable to activate constraint with anchors 
<NSLayoutXAxisAnchor:0x280fea300 \"i6.I6FuelSheetTextField:0x1030fe400.centerX\"> and 
<NSLayoutXAxisAnchor:0x280fea440 
\"UILayoutGuide:0x282327800'UIViewSafeAreaLayoutGuide'.centerX\"> because they have no common 
ancestor.  Does the constraint or its anchors reference items in different view hierarchies?  
That's illegal."

我如何确定这些地址指的是哪个视图?

swift xcode uiview autolayout
1个回答
0
投票

之所以发生这种情况,是因为您试图约束两个彼此不相关的视图。您很幸运能够从错误中获取足够的信息。您正在使用I6FuelSheetTextField实例的组件,并且尝试限制其centerX属性。因此,我认为该错误本身是可以解释的。

注意:当您忘记将视图添加到另一个视图的子视图时,也可能是这种情况。

© www.soinside.com 2019 - 2024. All rights reserved.