I'm creating an expandable cell with labels and picker view
xib
Cell Implementation
class PickerViewCell: UITableViewCell {
@IBOutlet weak var detailLabel: UILabel!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var height: NSLayoutConstraint!
@IBOutlet weak var picker: UIDatePicker!
var isExpanded:Bool = false
{
didSet
{
if isExpanded == false{
self.height.constant = 0.0
self.picker.hidden = true
}
else{
self.height.constant = 200.0
self.picker.hidden = false
}
}
}
override func awakeFromNib() {
self.height.constant = 0.0
super.awakeFromNib()
}
Delegate method
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
guard let cell = tableView.cellForRowAtIndexPath(indexPath) as? PickerViewCell else { return }
cell.isExpanded = !cell.isExpanded
print(cell.isExpanded)
UIView.animateWithDuration(0.3) {
cell.contentView.layoutIfNeeded()
}
tableView.beginUpdates()
tableView.endUpdates()
tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Top, animated: true)
}
I keep getting runtime warining about breaking constraints.
I set up a symbolic breakpoint and what I found out is that this line
self.height.constant = 200.0
inside cell implementation is the reason of the warning.
However, I found out that it happens only during the first tap on a given cell, after the initial tap I can tap multiple times, expanding and closing it each time, and the warning does not occur. Should I even care about this runtime warning?
EDIT:
I forgot to show datePicker constraints including those on height and aspect ratio:
Also it's worth to mention that I utilize
self.tableView.estimatedRowHeight = 100.0
self.tableView.rowHeight = UITableViewAutomaticDimension
in my viewController