I read an item by QR, consume a service and with that information I fill the UICollectionView. The first time I do this, I have no problem
Then when the second time, I have this
The log is:
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.
2020-04-21 17:25:56.172441-0500 Franz Mayer[878:58894] [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:0x281b9d130 Franz_Mayer.InfoCollectionViewCell_:0x10441da00.width == 351 (active)>",
"<NSLayoutConstraint:0x281bf0370 'UIView-Encapsulated-Layout-Width' Franz_Mayer.InfoCollectionViewCell_:0x10441da00.width == 1 (active)>"
)
The cell is
class InfoCollectionViewCell_: UICollectionViewCell {
let lHeader: UILabel = {
let uILabel = UILabel()
uILabel.textColor = UIColor.black
uILabel.layer.masksToBounds = true
uILabel.numberOfLines = 2
uILabel.translatesAutoresizingMaskIntoConstraints = false
return uILabel
}()
let lDescription: UILabel = {
let uILabel = UILabel()
uILabel.textColor = UIColor.black
uILabel.layer.masksToBounds = true
uILabel.numberOfLines = 100
uILabel.translatesAutoresizingMaskIntoConstraints = false
return uILabel
}()
override init(frame: CGRect) {
super.init(frame: frame)
awakeFromNib()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.contentView.translatesAutoresizingMaskIntoConstraints = false
//let widthConstraint = widthAnchor.constraint(equalToConstant: 400)
widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.size.width - (2 * 12)).isActive = true
addSubview(lHeader)
lHeader.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor).isActive = true
lHeader.leftAnchor.constraint(equalTo: safeAreaLayoutGuide.leftAnchor).isActive = true
lHeader.rightAnchor.constraint(equalTo: safeAreaLayoutGuide.rightAnchor).isActive = true
addSubview(lDescription)
lDescription.topAnchor.constraint(equalTo: lHeader.bottomAnchor).isActive = true
lDescription.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
lDescription.leftAnchor.constraint(equalTo: safeAreaLayoutGuide.leftAnchor).isActive = true
lDescription.rightAnchor.constraint(equalTo: safeAreaLayoutGuide.rightAnchor).isActive = true
/*let screenWidth = UIScreen.main.bounds.size.width
widthConstraint.constant = screenWidth - (2 * 12)*/
let sizes = Sizes.instance()
Utils.autoResizeFont(uiElementText: lHeader, size: sizes.LABEL_PAGE_MESSAGE, isBold: true)
Utils.autoResizeFont(uiElementText: lDescription, size: sizes.LABEL_PAGE_MESSAGE, isBold: false)
}
}
In the viewDidLoad on my Viewcontroller:
collectionView!.register(InfoCollectionViewCell_.self, forCellWithReuseIdentifier: "InfoCollectionViewCell_")
if let flowLayout = collectionView!.collectionViewLayout as? UICollectionViewFlowLayout {
flowLayout.estimatedItemSize = CGSize(width: 1,height: 1)
}
collectionView!.dataSource = self
And
datos = object.datos!
collectionView!.dataSource = self
collectionView!.reloadData()
How can I solve this problem ? Because the first time is OK, but after that I have te problem, but if I scrolled de Collection, the view back the view corrects itself.