5

有时我不断收到这样的错误 - 没有任何暗示 TextView 或 Button 的含义:

    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.

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

文本:

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

不幸的是没有多大帮助,因为我不知道这是代码中的哪个约束

4

1 回答 1

7

你是这样读的:

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

所以这是一个强制 textview 高 65 点的约束。在那里,您还有一个约束将该文本视图固定到距其父视图顶部边缘 134 点的位置:

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

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

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

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

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

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

在您的应用程序的某个地方,您必须有一个带有文本字段和两个按钮的视图。如果您中断所有异常,您可以注销日志中给出的各种地址并找出超级视图等如果您不确定,但希望您能够从中解决问题。

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

于 2013-04-08T09:15:22.207 回答