Reputation: 253
I have a Viewcontroller ThirdViewControllerPassenger
which has multiple subviews on it, including a UICollectionView
called collectionView
with horizontally scrolling Cards. So far, so good. I have written code to be executed from a tap action from inside the uicollectionviewcells. Tapping the action does work and prints to console. However, by pressing one of these cards I want to hide the whole UICollectionView
. I have set up an onTap Function as shown here:
@objc func onTap(_ gesture: UIGestureRecognizer) {
if (gesture.state == .ended) {
/* action */
if favCoordinate.latitude == 1.0 && favCoordinate.longitude == 1.0 {
//There has been an error OR the User has pressed the new Address button
//do
}else{
ThirdViewControllerPassenger().collectionView.isHidden = true
if ThirdViewControllerPassenger().collectionView.isHidden == true {
print("done!")
}
}
}
}
As you can see, I have already been troubleshooting a bit. I have tested ThirdViewControllerPassenger().collectionView.isHidden = true
from ThirdViewControllerPassenger
directly, which worked. It does not work, however, from a cell. The "done!" print never gets printed to console, so the call never arrives. I wonder why or what I am doing wrong.
Don't mind the first if statement, that function is not written yet. That should not matter. I am guessing that the rest of my code would not lead to any more clues.
Upvotes: 0
Views: 188
Reputation: 100523
Every ThirdViewControllerPassenger()
here
ThirdViewControllerPassenger().collectionView.isHidden = true
if ThirdViewControllerPassenger().collectionView.isHidden == true {
print("done!")
}
is a new instance not the real one , you need to get access to the real shown istance
delegate.collectionView.isHidden = true
if delegate.collectionView.isHidden == true {
print("done!")
}
Upvotes: 3