Swift : 如何检查哪个视图导致约束错误
Swift : how to check which view is causing constraints error
我在尝试加载 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."
如何确定这些地址指的是哪些视图?
发生这种情况是因为您试图限制彼此不相关的两个视图。您很幸运能够从错误中获得足够的信息。您正在使用一个 I6FuelSheetTextField
实例的组件,并且您试图限制它的 centerX
属性。所以,我认为错误本身是很好解释的。
注意:当您忘记将视图添加到另一个视图的子视图时,也可能是这种情况。
我在尝试加载 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."
如何确定这些地址指的是哪些视图?
发生这种情况是因为您试图限制彼此不相关的两个视图。您很幸运能够从错误中获得足够的信息。您正在使用一个 I6FuelSheetTextField
实例的组件,并且您试图限制它的 centerX
属性。所以,我认为错误本身是很好解释的。
注意:当您忘记将视图添加到另一个视图的子视图时,也可能是这种情况。