0
我已經有這個問題已經有幾天了,仍然沒有找到修復。基本上我試圖創建一個UITableView
自我大小的單元格。我已經設置了單元格高度爲UITableViewAutomaticDimension
。單元格的高度受限制以測試我的代碼,因爲此約束條件應確定單元格的高度。下面是我對電池的約束:動態tableview單元格,防止創建自動高度約束
let views = ["view": view]
self.addConstraints(NSLayoutConstraint.constraints(
withVisualFormat: "H:|[view]|",
options: [],
metrics: nil,
views: views
))
self.addConstraints(NSLayoutConstraint.constraints(
withVisualFormat: "V:|[view]|",
options: [],
metrics: nil,
views: views
))
NSLayoutConstraint(item: contentView, attribute: .width, relatedBy: .equal, toItem: self.superview!, attribute: .width, multiplier: 1, constant: 0).isActive = true
,這裏是錯誤消息我得到:
2017-04-17 22:40:01.596805-0300 ViraVira-Info[52208:1001696] [LayoutConstraints] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x600000099190 h=--& v=--& UITableViewCellContentView:0x7f987070f5f0.height == 44.5 (active)>",
"<NSLayoutConstraint:0x6000000966c0 UIView:0x7f9870709be0.height == 100 (active)>",
"<NSLayoutConstraint:0x600000098dd0 V:|-(0)-[UIView:0x7f9870709be0] (active, names: '|':UITableViewCellContentView:0x7f987070f5f0)>",
"<NSLayoutConstraint:0x600000098e70 V:[UIView:0x7f9870709be0]-(0)-| (active, names: '|':UITableViewCellContentView:0x7f987070f5f0)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000000966c0 UIView:0x7f9870709be0.height == 100 (active)>
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.
正如你可以看到tableview
自動創建一個height constraint
這與我的其他高度約束衝突。
"<NSAutoresizingMaskLayoutConstraint:0x600000099190 h=--& v=--& UITableViewCellContentView:0x7f987070f5f0.height == 44.5 (active)>"
但我找不到方法來刪除或防止發生這種約束。我已經嘗試將內容視圖的translatesAutoresizingMask
設置爲false,將其自身的單元格視圖和要添加到內容視圖的UIView
設置爲false,但未成功。這樣做給了我以下錯誤:
Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a `tableview cell's` content view. We're considering the collapse unintentional and using standard height instead.
請要求任何額外的信息,我會高興地把它添加到這個問題。
view.translatesAutoresizingMaskIntoConstraints =假 應該幫助@ J.Paravicini – Shial
你有紅色的問題?我說,我已經嘗試了,但沒有成功:/ –
試試cell.contentView.translatesAutoresizingMaskIntoConstraints – Shial