Я читаю элемент по QR, использую сервис, и этой информацией я заполняю UICollectionView. Первый раз, когда я делаю это, у меня нет проблем
Затем, когда во второй раз, у меня это
Журнал:
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)>"
)
Ячейка
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)
}
}
В viewDidLoad на моем Viewcontroller:
collectionView!.register(InfoCollectionViewCell_.self, forCellWithReuseIdentifier: "InfoCollectionViewCell_")
if let flowLayout = collectionView!.collectionViewLayout as? UICollectionViewFlowLayout {
flowLayout.estimatedItemSize = CGSize(width: 1,height: 1)
}
collectionView!.dataSource = self
И
datos = object.datos!
collectionView!.dataSource = self
collectionView!.reloadData()
Как я могу решить эту проблему? Потому что в первый раз все в порядке, но после этого у меня возникла проблема, но если я прокрутил de Collection, представление назад, представление исправляет себя.