How to programmatically select cell in collectionView in swift 3?

Viewed 8841

I'm new to swift and been having trouble programmatically selecting collectionview cells in collectionView. I've found only instructions for tableview but ran into an error when tried to implement it.

 let indexPath = IndexPath(row: 0, section: 0)
    appsCollectionView.selectItem(at: indexPath, animated: false, scrollPosition: .bottom)
    appsCollectionView.delegate?.collectionView!(appsCollectionView, didSelectItemAt: indexPath)

According to other answers, you need both lines 2 and 3. Not sure what line 3 is doing. When I try to run this code, I got the error

collectionView:didSelectItemAtIndexPath:]: unrecognized selector sent to instance

Thanks!

2 Answers
Related