Я столкнулся с этой проблемой уже несколько дней и до сих пор не нашел решения. В основном я пытаюсь создать UITableView
с ячейками с самодиагностикой. Я установил автоматическую высоту ячеек с помощью UITableViewAutomaticDimension
. Высота ячейки ограничена для проверки моего кода, поскольку это ограничение должно определять высоту ячейки. Вот мои ограничения для ячейки:
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
, добавляемого в представление содержимого, но безуспешно. Это привело к следующей ошибке:
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.
Пожалуйста, запрашивайте дополнительную информацию, и я с радостью добавлю ее к этому вопросу.