user3708224
user3708224

Reputation: 1259

Horizontal Scrolling collection View issue

I am trying to scroll horizontally to a collectionView when I call a function and am receiving the error 'none' is unavailable: use [] to construct an empty option set - not sure what is wrong here...Thanks in advance!

  func handleSearch() {
        scrollToMenuIndex(menuIndex: 2)
    }

    func scrollToMenuIndex(menuIndex: Int) {
        let indexPath = NSIndexPath(item: menuIndex, section: 0)
        collectionView?.scrollToItem(at: indexPath as IndexPath, at: .none, animated: true)
    }

Upvotes: 0

Views: 113

Answers (1)

Mihai Fratu
Mihai Fratu

Reputation: 7663

You have to provide a position where the item should be scrolled to. See the documentation for UICollectionViewScrollPosition for possible values. In the meantime you could use this:

collectionView?.scrollToItem(at: indexPath as IndexPath, at: .left, animated: true)

Upvotes: 1

Related Questions