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()
}
}
答案 0 :(得分:0)
您是正确的,您需要使用UIControl
或UIGestureRecognizer
。看起来您在示例代码中添加了这两个代码,UIGestureRecognizer
正在消耗触摸而非按钮。