S.M_Emamian
S.M_Emamian

Reputation: 17393

CollectionView didSelectItemAtIndexPath doesn't work - Swift

I would like to use didSelectItemAtIndexPath but it doesn't work.

    collection_contactus.allowsSelection = true
    collection_options.allowsSelection = true

    collection_options!.dataSource = self
    collection_options!.delegate = self

    collection_contactus!.dataSource = self
    collection_contactus!.delegate = self

    func collectionView(_ collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
       print("test")
//        if(collectionView == collection_options)
//        {
//
//        }else{
//            print("test: \(indexPath)")
//        }
    }

I can't see any output.

Upvotes: 1

Views: 484

Answers (1)

Ozgur Vatansever
Ozgur Vatansever

Reputation: 52213

I think you are using Swift 3.2. That method was renamed to collectionView(_:didSelectItemAt:) in Swift 3.0:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  ...
}

Upvotes: 1

Related Questions