【问题标题】:CollectionView didSelectItemAtIndexPath doesn't work - SwiftCollectionView didSelectItemAtIndexPath 不起作用 - Swift
【发布时间】:2018-04-14 00:14:19
【问题描述】:

我想使用didSelectItemAtIndexPath,但它不起作用。

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

我看不到任何输出。

【问题讨论】:

  • 使用正确的方法签名会有很大帮助。

标签: ios swift uicollectionview


【解决方案1】:

我认为您使用的是 Swift 3.2。该方法在 Swift 3.0 中重命名为 collectionView(_:didSelectItemAt:)

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

【讨论】:

  • 仅供参考 - 它在 Swift 3.0 中被重命名,而不是 3.2。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-26
  • 2016-06-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多