Swift Collectionview didSelectItemAtIndexPath不起作用

时间:2016-09-15 15:43:46

标签: ios swift uicollectionview

我有自定义单元格(xib文件)的UICollectionView,我设法显示集合视图,但我没有设法检测何时点击具有该功能的单元格:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){

通常,我设法做到这一点,但这次我不知道为什么它不起作用。实际上我正在使用这个播客" https://cocoapods.org/pods/SACollectionViewVerticalScalingFlowLayout"

我的代码是:

class ProjectsController: UIViewController {
    @IBOutlet weak var collectionViewGridFormat: UICollectionView!

    override func viewDidLoad() {
        super.viewDidLoad()
        collectionViewGridFormat.registerNib(UINib(nibName: "ProjectsGridFormatCell", bundle: nil), forCellWithReuseIdentifier: "cellProjectGrid")

...


    }
}

extension ProjectsController: UICollectionViewDataSource, UICollectionViewDelegate {
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 30
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell : ProjectsGridFormatCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellProjectGrid", forIndexPath: indexPath) as! ProjectsGridFormatCell

        cell.lblProjectName.text = "Test project"

        return cell
    }

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
        print("aa")
    }
}

但是当我点击一个单元格时,"打印(" aa")"没有显示。

我是否提供了足够的信息? :)

感谢您的帮助! :d

此致

1 个答案:

答案 0 :(得分:0)

在故事板中的Identity Inspector下检查“已启用用户交互”吗?