swift - UICollectionView viewForSupplementaryElementOfKind didSelect

标签 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()
    }
}

最佳答案

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

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

相关文章:

swift - 如何在 ScrollView 中为垂直堆栈 View 设置自动布局约束

Swift 结构扩展 : 'Cannot convert return expression of type <type> to return type <type>'

ios - 在 UIButton 上显示第二个 ImageView

ios - 无法显示导航 View

ios - 如何使用透明导航栏和工具栏正确地动画推送 View Controller ?

swift - 定义+时自动定义+=?

ios - UIButton 闪烁动画

ios - 如何添加位于其他 View 下方的阴影

ios - 如何在我的触摸位置获取层次结构中的所有 View - Swift

swift - map 中的 SF 符号不会应用颜色