2015-04-20 161 views
1

我在TableViewCell中有一個動態大小的標籤。我已將它固定到上,下,左和右,並將行設置爲0,它工作正常。接下來,我在標籤下面添加一個按鈕並將其固定到頂部和左側。並修復寬度和高度。但我在運行時動態添加按鈕TableViewCell

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:0x7fcbc302f600 UILabel:0x7fcbc3034010'Digestion of food in the...'.top == UITableViewCellContentView:0x7fcbc30334a0.topMargin>", 
"<NSLayoutConstraint:0x7fcbc3037e30 UITableViewCellContentView:0x7fcbc30334a0.bottomMargin == UILabel:0x7fcbc3034010'Digestion of food in the...'.bottom + 38>", 
    "<NSLayoutConstraint:0x7fcbc303a920 'UIView-Encapsulated-Layout-Height' V: [UITableViewCellContentView:0x7fcbc30334a0(43.5)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fcbc3037e30 
UITableViewCellContentView:0x7fcbc30334a0.bottomMargin == 
UILabel:0x7fcbc3034010'Digestion of food in the...'.bottom + 38> 

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. Here is the screenshot of my layout 

Screenshot

得到一個錯誤,我應該刪除哪些約束?我認爲我沒有添加額外的約束

回答

1

在界面構建器中檢查是否沒有警告(vc檢查器側面的黃色箭頭)並檢查標籤的高度+按鈕和邊距是否不會超過細胞的高度。

你還說你固定在頂部,是什麼?容器或標籤?

+0

細胞高度動態化標籤的大小。我只想讓按鈕出現在標籤文字下方。固定在標籤的頂部 –

+0

然後,應將按鈕的頂部固定到標籤的底部。這是一個自定義單元格,我想對不對?你可以顯示你的佈局的屏幕?確保標籤高度不超過單元的高度。 – jalone

+0

你可以檢查一次佈局嗎? –

0
      (OR) 

出於某些原因,Xcode中產生一個NIB在構建時的自動佈局約束自己的默認設置。這就是爲什麼我不能添加任何手動約束,因爲它們與自動添加的約束相沖突。

我解決了這個方式如下:

打開你處理故事板視圖控制器。

選擇視圖控制器,並選擇編輯>解決自動佈局問題> []中視圖控制器的所有視圖>從菜單中添加缺少的約束: enter image description here

這將確保不產生額外的建造時間限制和所有約束現在都可見.-->從您的視圖控制器中選擇所有約束: enter image description here

這將確保不會創建額外的構建時間約束,並且所有約束現在都可見。右窗格中顯示以下複選框:佔位符 - 從buil刪除d時間:

enter image description here

(這將確保沒有額外的編譯時間約束創建並且所有的約束,現在是可見的)

現在你可以在代碼中手動添加的所有汽車佈局限制。

+0

是的,但這通常意味着自動粘貼的不良使用,甚至更多,因爲它突然告訴你存在佈局問題(res標記) – jalone

0

你將不得不提供比你關於汽車的佈局像的UILabel的距上邊緣的距離設置的值一些更多的信息,下,左等

的問題可能是你所指定的的UIButton從上邊緣開始,它應該與您的UILabel相同,因此它將UIButton的垂直間距屬性設置爲UILabel,以確保UIButton位於其下方。