I have a collectionView with two cells. Each cell fits the size of the screen.
In the first cell I have some buttons.
When I tap a button, the collectionView scrolls to the second cell and depending on which button I tapped, the second cell should show a different view.
This code is to reference the second cell when I tap on a button:
if let cell = collectionView.cellForItem(at: secondIndexPath) as? SecondCell {
// change the view of the cell
print("Does not execute code")
}
I guess cellForItem(at: IndexPath) is nil because the cell is out of bounds.
But how can I fix this?