2017-11-01 6 views
1

didSelectItemAtIndexPathを使用したいと思いますが、動作しません。CollectionView didSelectItemAtIndexPathが機能しません - Swift

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)") 
//  } 
    } 

これは私のクラスの全体です:

https://paste.ofcode.org/HYhLpnDFQFaNfma8LKGdZp

私は任意の出力を参照してください傾けます。

+1

正しいメソッドのシグネチャを使用すると、多くのことをするのに役立ちます。 – rmaddy

答えて

1

あなたはSwift 3.2を使用していると思います。その方法は、スウィフト3.0にcollectionView(_:didSelectItemAt:)に名前が変更されました:

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

FYI - 3.2ではなくSwift 3.0で名前が変更されました。 – rmaddy

関連する問題