I have a stackView(called 'btnStack') which holds four buttons in a cell(class 'PresentationCell') which I am trying to hide with the following code:
func hideBtnStack() {
let cell = collectionView.visibleCells.first as! PresentationCell
cell.btnStack.isHidden = true
}
However, when I run the code I get the following error:
'Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value'
Is there an easier/better way to access the btnStack in the cell?
The relevant code in cellForRowAt is:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! PresentationCell
}
I also have the btnStack declared in the PresentationCell class as follows:
class PresentationCell: UICollectionViewCell {
@IBOutlet weak var textView: UITextView!
@IBOutlet weak var btnStack: UIStackView!
}
And I first call the hideBtnStack method in the ViewDidLoad as follows:
override func viewDidLoad() {
super.viewDidLoad()
collectionView.dataSource = self
collectionView.delegate = self
setUpCollectionView()
hideNavBar()
hideBtnStack()
}
Thanks in advance for any help that you can provide.