I'm trying to get a minimum cell height for a tableView cell. This works, but it throws a zillion of warnings into the debugger console of Xcode.
Question 1: Why?
Question 2: How to get rid of these warnings while implementing a minimum cell height?
2018-11-16 19:18:13.080131+0100 Test[46195:5492055] [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.
(
"<NSLayoutConstraint:0x600003a91450 V:[UILabel:0x7fa4f2e05470'One ']-(0)-| (active, names: '|':UITableViewCellContentView:0x7fa4f2e17f70 )>",
"<NSLayoutConstraint:0x600003a91310 V:|-(0)-[UILabel:0x7fa4f2e05470'One '] (active, names: '|':UITableViewCellContentView:0x7fa4f2e17f70 )>",
"<NSLayoutConstraint:0x600003a911d0 UILabel:0x7fa4f2e05470'One '.height >= 44 (active)>",
"<NSLayoutConstraint:0x600003a8dbd0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fa4f2e17f70.height == 44 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600003a911d0 UILabel:0x7fa4f2e05470'One '.height >= 44 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2018-11-16 19:18:13.081005+0100 Test[46195:5492055] [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.
(
"<NSLayoutConstraint:0x600003a953b0 V:[UILabel:0x7fa4f2c018d0'Three ']-(0)-| (active, names: '|':UITableViewCellContentView:0x7fa4f2c06510 )>",
"<NSLayoutConstraint:0x600003a95450 V:|-(0)-[UILabel:0x7fa4f2c018d0'Three '] (active, names: '|':UITableViewCellContentView:0x7fa4f2c06510 )>",
"<NSLayoutConstraint:0x600003a94be0 UILabel:0x7fa4f2c018d0'Three '.height >= 44 (active)>",
"<NSLayoutConstraint:0x600003a95cc0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fa4f2c06510.height == 44 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600003a94be0 UILabel:0x7fa4f2c018d0'Three '.height >= 44 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
This can be simply reproduced with this very simple setup:
- New UITableView with controller MyTableView
- 1 prototype cell with class MyTableViewCell
- Cell has 1 label linked to MyTableViewCell.label
I have the following constrains for the label:
This is to make sure I have a minimum cell height of 44.
The view controller:
import UIKit
class MyTableViewController: UITableViewController {
let data: [String] = [
"One ",
"Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two ",
"Three "
]
override func viewDidLoad() {
super.viewDidLoad()
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableView.automaticDimension
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) as! MyTableViewCell
cell.label.text = data[indexPath.row]
return cell
}
}
The cell:
import UIKit
class MyTableViewCell: UITableViewCell {
@IBOutlet weak var label: UILabel!
}