UICollectionView viewForSupplementaryElementOfKind didSelect

时间:2016-03-29 14:22:57

标签: swift uikit

viewForSupplementaryElementOfKind中的选择如何被识别?我已经尝试将目标添加到header中的按钮,但这不起作用。选择操作是发送到didSelectItemAtIndexPath还是还有别的?标题的所有元素都在UIStackView

之内
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()
    }
}

1 个答案:

答案 0 :(得分:0)

您是正确的,您需要使用UIControlUIGestureRecognizer。看起来您在示例代码中添加了这两个代码,UIGestureRecognizer正在消耗触摸而非按钮。