2013-04-08 36 views
4

有時候,我不斷收到這樣的錯誤,這些 - 沒有任何提示到的TextView或按鈕是指:如何找到崩潰約束?

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)]> 

遺憾的是沒有太大的幫助,因爲我沒有任何想法,這約束,這是在代碼

+0

可能重複的[無法同時滿足約束 - 沒有約束到位](http://stackoverflow.com/questions/14327145/unable-to-simultaneously-satisfy-constraints-no-constraints-in-place) - 在閱讀這些日誌時有幫助 – jrturton 2013-04-08 09:05:20

回答

6

你喜歡這個閱讀:

<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]> 

很可能是你不希望所有這些限制。這裏有兩個約束試圖垂直放置文本視圖(基於按鈕,並且基於超級視圖頂部的絕對間距)。

在您的應用程序中的某個位置,您必須有一個帶有文本字段和兩個按鈕的視圖。如果你打破了所有的例外情況,你可以註銷日誌中給出的各種地址,並且如果你不確定,找出超級瀏覽等等,但是希望你能從中解決這個問題。

有時是有幫助的日誌複製到一個文本編輯器,找到/文字代替地址,以便更容易閱讀。

+4

非常感謝您的詳細解釋。我也只是把一個像NSLog(@「ok_btnTV%p」,_ ok_btnTV); 現在在我的viewDidAppear找到有問題的視圖。現在花了不到10秒的時間才發現問題! - 這個「超級先進的用戶界面生成器」有什麼古老的方式來找到這樣的問題......非常感謝! – user387184 2013-04-08 09:20:20