2015-12-10 71 views
1

我有一個tableview單元格,裏面有一個imageview和一個按鈕。我爲imageview和按鈕添加約束。桌面視圖出現,單元顯示正確。但是當重用單元格時,我向下滾動tableView並向上滾動,單元格顯示錯誤?如何在swift中重用tableviewCell和autoLayout?

當我重複使用單元格時,我添加了新的約束條件,與之前的約束條件存在衝突,我嘗試在添加新的約束條件之前刪除先前的約束條件,但不起作用。下面是該項目鏈接:

https://github.com/chengyanan/chat

在自動佈局錯誤的情況下拋出控制檯的警告:

2015-12-10 16:34:30.299 Chat[5488:133086] 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. 
(
    "<NSLayoutConstraint:0x7cc5b120 H:[UIImageView:0x7c94daa0(30)]>", 
    "<NSLayoutConstraint:0x7cc5a640 H:|-(8)-[UIImageView:0x7c94daa0](LTR) (Names: '|':UITableViewCellContentView:0x7c96bdb0)>", 
    "<NSLayoutConstraint:0x7ccab9e0 UIImageView:0x7c94daa0.right == UITableViewCellContentView:0x7c96bdb0.right - 8>", 
    "<NSLayoutConstraint:0x7cc71dc0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7c96bdb0(320)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7ccab9e0 UIImageView:0x7c94daa0.right == UITableViewCellContentView:0x7c96bdb0.right - 8> 

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. 
2015-12-10 16:34:30.300 Chat[5488:133086] 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. 
(
    "<NSLayoutConstraint:0x7cc5b120 H:[UIImageView:0x7c94daa0(30)]>", 
    "<NSLayoutConstraint:0x7cc59d40 H:[UIImageView:0x7c94daa0]-(3)-[UIButton:0x7c95b8b0'Trgghhh hhhhhhhhhhhbbbbbv...'](LTR)>", 
    "<NSLayoutConstraint:0x7cc78640 H:[UIButton:0x7c95b8b0'Trgghhh hhhhhhhhhhhbbbbbv...'(255)]>", 
    "<NSLayoutConstraint:0x7ccc99f0 UIButton:0x7c95b8b0'Trgghhh hhhhhhhhhhhbbbbbv...'.right == UIImageView:0x7c94daa0.left - 3>" 
) 

enter image description here

+0

這可以幫助你http://stackoverflow.com/a/18746930/452584 – LuckyStarr

+0

爲什麼不創建2個不同的單元格作爲故事板的回覆/回答,而不是在代碼中創建它並通過代碼添加約束,泡泡可以是輕鬆創建代碼而不是使用uiimage ... – Tj3n

回答

0

你需要隨時刪除和添加新的限制?你可以在cellForRowAtIndexPath中修改UITableViewCell方法中的當前約束嗎?它會正確佈局。

相關問題