簡體   English   中英

如何解決NSLayoutConstraint錯誤?

[英]How to Troubleshoot NSLayoutConstraint errors?

我的應用程序中有一個UITableView。 它填充了一個稱為“課程單元格”的自定義UITableCell。 看起來像這樣http://i.imgur.com/VoCxkJa.png

每當加載此視圖時。 它顯示了許多布局錯誤,如下所示。 但是在我的Interface Builder上看起來還不錯。 我研究並嘗試了很多解決此錯誤的方法。

請幫幫我。 提前致謝

2015-08-17 12:25:51.543 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:0x7f85706d4150 UILabel:0x7f85706eb5c0'How Old are You?'.leading == UITableViewCellContentView:0x7f85706ce730.leadingMargin + 8>",
    "<NSLayoutConstraint:0x7f85706c6450 UITableViewCellContentView:0x7f85706ce730.trailingMargin == UILabel:0x7f85706eb5c0'How Old are You?'.trailing + 50>",
    "<NSLayoutConstraint:0x7f85706e7710 'fittingSizeHTarget' H:[UITableViewCellContentView:0x7f85706ce730(34)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f85706c6450 UITableViewCellContentView:0x7f85706ce730.trailingMargin == UILabel:0x7f85706eb5c0'How Old are You?'.trailing + 50>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

編輯

我在View Controller中使用動態表View Cell。 可能引起任何問題嗎?

   LessonTable.estimatedRowHeight = 120
   LessonTable.rowHeight = UITableViewAutomaticDimension

您對於UILabel:0x7f85706eb5c0'How Old are You?'.trailing + 50>約束沖突UILabel:0x7f85706eb5c0'How Old are You?'.trailing + 50>為您的情況輕松解決它,只需添加擁抱UILabel的優先級即可。

來自代碼:

[urLabelCell setContentHuggingPriority:UILayoutPriorityFittingSizeLevel forAxis:UILayoutConstraintAxisHorizontal];
[urLabelCell setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[urLabelCell setContentCompressionResistancePriority:UILayoutPriorityFittingSizeLevel forAxis:UILayoutConstraintAxisHorizontal];
[urLabelCell setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];

或在IB中:

在此處輸入圖片說明

並刪除以下規則之一:

"<NSLayoutConstraint:0x7f85706d4150 UILabel:0x7f85706eb5c0'How Old are You?'.leading == UITableViewCellContentView:0x7f85706ce730.leadingMargin + 8>",
    "<NSLayoutConstraint:0x7f85706c6450 UITableViewCellContentView:0x7f85706ce730.trailingMargin == UILabel:0x7f85706eb5c0'How Old are You?'.trailing + 50>",

或設置不同的優先級

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM