简体   繁体   English

CollectionView didSelectItemAtIndexPath 不起作用 - Swift

[英]CollectionView didSelectItemAtIndexPath doesn't work - Swift

I would like to use didSelectItemAtIndexPath but it doesn't work.我想使用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)")
//        }
    }

I can't see any output.我看不到任何输出。

I think you are using Swift 3.2.我认为您正在使用 Swift 3.2。 That method was renamed to collectionView(_:didSelectItemAt:) in Swift 3.0:该方法在 Swift 3.0 中被重命名为collectionView(_:didSelectItemAt:)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 didSelectItemAtIndexPath在集合视图Swift中不起作用 - didSelectItemAtIndexPath Doesn't Work In Collection View Swift Swift Collectionview didSelectItemAtIndexPath不起作用 - Swift Collectionview didSelectItemAtIndexPath not working (快速)在外部视图中定义的UICollectionView中的didSelectItemAtIndexPath不起作用 - (Swift) didSelectItemAtIndexPath in UICollectionView defined in external view doesn't work didSelectItemAtIndexPath无法正常工作 - didSelectItemAtIndexPath doesn't work normally 斯威夫特:didSelectItemAtIndexpath函数不适用于json - Swift: didSelectItemAtIndexpath function not work of json CollectionView无法正常工作 - CollectionView doesn't work properly 如果滚动,swift collectionview单元格didSelectItemAtIndexPath显示错误的单元格 - swift collectionview cell didSelectItemAtIndexPath shows wrong cell if you scroll 当superview具有手势时,collectionView没有调用didSelectItemAtIndexPath - collectionView didn't call didSelectItemAtIndexPath when superview has gesture iOS在didSelectItemAtIndexPath展开CollectionView - iOS unwind CollectionView at didSelectItemAtIndexPath iOS为什么不能从UITapGestureRecognizer调用方法collectionView:didSelectItemAtIndexPath :? - iOS Why can't the method collectionView:didSelectItemAtIndexPath: be called from UITapGestureRecognizer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM