I have a collectionView that is the width of the screen and I need it to switch to the next section instead to retrieve the one out of view on the right. I happen to get it where it works 1 time with this code and then it stops working, although the program works fine with no errors.
@objc func RightButtonClick(button1: UIButton) {
let indexOfCell = button1.tag
let visibleItems: NSArray = self.CollectionView2.indexPathsForVisibleItems as NSArray
let currentItem: IndexPath = visibleItems.object(at: 0) as! IndexPath
let nextItem: IndexPath = IndexPath(item: currentItem.item + indexOfCell, section: 0)
if nextItem.row == CollectionView2.numberOfSections {
self.CollectionView2.scrollToItem(at: nextItem, at: .left, animated: true)
}
}
}