如何识别 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()
}
}
最佳答案
您是正确的,您需要使用 UIControl
或 UIGestureRecognizer
。看起来您正在示例代码中添加两者,并且 UIGestureRecognizer
正在消耗触摸而不是按钮。
关于swift - UICollectionView viewForSupplementaryElementOfKind didSelect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36287119/