如何找到崩溃的约束? [英] How to find the crashing constraint?

查看:198
本文介绍了如何找到崩溃的约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我会收到类似这样的错误 - 没有任何提示TextView或Button的含义:

 无法同时满足约束。 
以下列表中的至少一个约束可能是您不想要的约束。尝试这样:(1)查看每个约束,并尝试找出你不期望的; (2)找到添加了不需要的约束或约束并修复它的代码。 (注意:如果你看到NSAutoresizingMaskLayoutConstraints,你不明白,请参阅UIView属性的文档翻译autoresizingMaskIntoConstraints)

< NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000 ]>,
< NSLayoutConstraint:0x11d77620 V:[UIButton:0x11d71cf0(44)]>,
< NSLayoutConstraint:0x11d7be30 V:[UIButton:0x11d79e70(43)]> ;,
< NSLayoutConstraint:0xa1980d0 V:| - (134) - [UITextView:0xc1bb000](Names:'|':UIView:0xa1afba0)>,
0xa119e50 V:[UIButton:0x11d79e70] - (61) - [UIButton:0x11d71cf0]>,$ b $ v $ UIButton: b< NSLayoutConstraint:0xa199cb0 V:| - (40) - [UIButton:0x11d79e70](名称:'|':UIView:0xa1afba0)>


通过断开约束恢复
< NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]>

打开objc_exception_throw在调试器中捕获它。
< UIKit / UIView.h>中列出的UIView上的UIConstraintBasedLayoutDebugging类别中的方法也可能有帮助。是否有一种方法来识别导致崩溃的代码中的约束?

有没有办法识别导致崩溃的代码中的约束?



文本:

 将尝试通过断开约束来恢复
< ; NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]>

很不幸,因为我不知道这是在代码

解决方案

这样阅读:

 < NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]> 
^约束类型^地址^轴^ VFL
中的描述

所以这是一个约束,强制textview是65点高。在这里,你还有一个约束将这个文本视图从它的超级视图的顶部边缘扩展到134个点:

 < NSLayoutConstraint:0xa1980d0 V :|  - (134) -  [UITextView:0xc1bb000](名称:'|':UIView:0xa1afba0)> 

一个约束将文本视图的Y中心固定到按钮的Y中心:

 < NSLayoutConstraint:0xa199ed0 UITextView:0xc1bb000.centerY == UIButton:0x11d71cf0.centerY> 

以及将按钮固定到特定垂直位置的约束:

 < NSLayoutConstraint:0xa199e50 V:[UIButton:0x11d79e70]  - (61) -  [UIButton:0x11d71cf0] 

很可能你不想要所有这些约束。这里有两个约束,试图垂直定位文本视图(基于按钮,并基于超级视图的顶部的绝对间距)。



在您应用程式的某个位置,您必须有一个包含文字栏位和两个按钮的检视。如果你打破了所有的异常,你可以注销日志中给出的各种地址,找出superviews等等,如果你不确定,但希望你能够从中工作。



有时,将日志复制到文本编辑器中并使用单词查找/替换地址,以便更容易阅读是有帮助的。


Sometimes I keep getting errors like these - without any hint to which TextView or Button is meant:

    Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]>",
    "<NSLayoutConstraint:0x11d77620 V:[UIButton:0x11d71cf0(44)]>",
    "<NSLayoutConstraint:0x11d7be30 V:[UIButton:0x11d79e70(43)]>",
    "<NSLayoutConstraint:0xa1980d0 V:|-(134)-[UITextView:0xc1bb000]   (Names: '|':UIView:0xa1afba0 )>",
    "<NSLayoutConstraint:0xa199ed0 UITextView:0xc1bb000.centerY == UIButton:0x11d71cf0.centerY>",
    "<NSLayoutConstraint:0xa199e50 V:[UIButton:0x11d79e70]-(61)-[UIButton:0x11d71cf0]>",
    "<NSLayoutConstraint:0xa199cb0 V:|-(40)-[UIButton:0x11d79e70]   (Names: '|':UIView:0xa1afba0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

Is there a way to identify the constraint in the code that is causing the crash?

The text:

  Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]>

unfortunately doesn't help much, since I do not have any idea which constraint this is in code

解决方案

You read them like this:

<NSLayoutConstraint:0x11d748d0 V:    [UITextView:0xc1bb000(65)]>
 ^ Constraint type  ^ Address  ^Axis ^Description in VFL
                      (of constraint)

So this is a constraint forcing the textview to be 65 points high. In there you also have a constraint pinning this text view to 134 points from its superview's top edge:

<NSLayoutConstraint:0xa1980d0 V:|-(134)-[UITextView:0xc1bb000]   (Names: '|':UIView:0xa1afba0 )>

And a constraint pinning the Y center of the text view to the Y center of a button:

<NSLayoutConstraint:0xa199ed0 UITextView:0xc1bb000.centerY == UIButton:0x11d71cf0.centerY>

And a constraint pinning the button itself to a specific vertical location:

<NSLayoutConstraint:0xa199e50 V:[UIButton:0x11d79e70]-(61)-[UIButton:0x11d71cf0]>

It is likely that you didn't want all these constraints. Here you have two constraints that are trying to position the text view vertically (based from the button, and based on absolute spacing from the top of the superview).

Somewhere in your app you must have a view with a text field and two buttons. If you break on all exceptions you can log out the various addresses given in the log and find out the superviews and so on if you're not sure, but hopefully you'll be able to work it out from this.

Sometimes it is helpful to copy the log into a text editor and find / replace the addresses with words so that it is easier to read.

这篇关于如何找到崩溃的约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆