2016-09-15 53 views
0

我UICollectionView與自定義單元格(XIB文件),我管理顯示的CollectionView,但我不管理,當我與功能的電池接頭檢測:斯威夫特的CollectionView didSelectItemAtIndexPath不工作

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

您是否將視圖控制器設置爲集合視圖的委託?您需要同時設置 - 委託和數據源。 – almas

回答

0

是「用戶交互啓用」下的身份督察故事板檢查?

+0

我在我的UICollectionViewCell中添加了「self.userInteractionEnabled = true」,並且在Inspector中,所有元素都啓用了它。但它仍然不起作用 – Adz