簡體   English   中英

Swift Collectionview didSelectItemAtIndexPath不起作用

[英]Swift Collectionview didSelectItemAtIndexPath not working

我有帶有自定義單元格(xib文件)的UICollectionView,我設法顯示collectionview,但是我沒有設法檢測何時點擊帶有函數的單元格:

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

但是,當我點擊一個單元格時,不會顯示“ print(“ aa”)“。

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

謝謝你的幫助 !! :D

問候,

在情節提要中的身份檢查器下是否選中了“已啟用用戶交互”?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM