2016-03-29 6 views
0

viewForSupplementaryElementOfKind内の選択はどのようにして認識されますか?私はheader内のボタンにターゲットを追加しようとしましたが、それは動作しません。選択アクションはdidSelectItemAtIndexPathに送信されますか、それとも他に何かありますか?そのヘッダのすべての要素は、あなたがUIControlUIGestureRecognizerを使用する必要があることを正しいUIStackViewUICollectionView viewForSupplementaryElementOfKind didSelect

override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { 

    if kind == UICollectionElementKindSectionHeader { 
     let cell = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "header", forIndexPath: indexPath) as! mainCell 
     let index = indexPath.section 
     cell.btnImg.af_setBackgroundImageForState(.Normal, URL: NSURL(string: "urrl")!) 
     cell.userImg.addTarget(self, action: #selector(MainController.showNextView(_:)), forControlEvents: .TouchUpInside) 
     let tap = UIGestureRecognizer(target: self, action: #selector(self.test)) 
     cell.addGestureRecognizer(tap) 
     return cell 
    } else { 

     return UICollectionReusableView() 
    } 
} 

答えて

0

内にあります。あなたのサンプルコードには、ボタンの代わりにタッチを消費しているUIGestureRecognizerの両方を追加しているようです。

関連する問題