gpt4 book ai didi

swift - UICollectionView viewForSupplementaryElementOfKind didSelect

转载 作者:行者123 更新时间:2023-11-30 13:34:00 24 4
gpt4 key购买 nike

如何识别 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()
}
}

最佳答案

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

关于swift - UICollectionView viewForSupplementaryElementOfKind didSelect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36287119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com