First of all, I don't use storyboard, I setup my elements in a UICollectionView
programmatically.
Depending I have items or not in my UICollectionView
, I display a UIView
at 16px or 88px from the top and for this, I use a switch
condition that doesn't seem to be respected.
I use a classical condition :
switch numberOfItems {
case 0:
print("nothing here")
holderButtons.isHidden = true
BottomView.anchor(top: bottomContainerView.topAnchor, leading: nil, bottom: nil, trailing: nil, padding: .init(top: 16, left: 0, bottom: 0, right: 0))
default:
print("1 or more")
holderButtons.isHidden = false
BottomView.anchor(top: bottomContainerView.topAnchor, leading: nil, bottom: nil, trailing: nil, padding: .init(top: 88, left: 0, bottom: 0, right: 0))
}
I also tried with a if...else
.
The condition works fine for the hidden view, but not for my BottomView
.
Here is the message from the debug area :
<NSLayoutConstraint:0x280f385a0 V:|-(16)-[UIView:0x1479337d0] (active, names: '|':UIView:0x147933410 )>",
"<NSLayoutConstraint:0x280f13930 V:|-(88)-[UIView:0x1479337d0] (active, names: '|':UIView:0x147933410 )>
I don't see what's the problem with it. Any idea ?
Ok, i finally added my condition to a "setupElements" func and it works fine : no more NSLayoutConstraint mistakes in my debug area. Even if I still have my initial problem when I scroll over my UICollectionView : I have a stretchy header and when I expand it until I don't see anymore my cells, it re-inits my condition... it's another problem :)