Perform Segue from UICollectionViewCell Button different from Cell Click

前端 未结 3 998
旧时难觅i
旧时难觅i 2021-02-06 15:27

I have a UICollectionViewCell, with a UIButton. And I have two different actions. The first one, when the user presses the cell, it will segue to anoth

3条回答
  •  春和景丽
    2021-02-06 16:14

    Another solution that also works like a charm:

    extension YOURViewController : UICollectionViewDataSource
    {
        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
        {
             let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "YOURCell", for: indexPath) as! YOURCollectionViewCell
    
             cell.butTapped = {
                 [weak self] (YOURCollectionViewCell) -> Void in
                 // do your actions when button tapped
             }
        }        
        return cell
    }
    
    
    class YOURCollectionViewCell: UICollectionViewCell
    {
         var butQRTapped: ((YOURCollectionViewCell) -> Void)?
         @IBAction func deleteButtonTapped(_ sender: AnyObject) {
             butTapped?(self)
         }
    }
    

提交回复
热议问题