简体   繁体   English

没有调用collectionView didSelectItemAt indexPath

[英]collectionView didSelectItemAt indexPath not being called

When attempting to select a cell in my collection view, nothing happens. 尝试在我的收藏夹视图中选择一个单元格时,没有任何反应。 I have my delegate set up but it does not get called when the user taps. 我已经设置了我的代表,但是当用户点击时它不会被调用。

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    print("cell selected")
}

The cell is a custom cell containing a CAShapeLayer and a UILabel. 该单元格是一个自定义单元格,其中包含CAShapeLayer和UILabel。 I have attempted to mess around with the isUserInteractionEnabled method to no avail. 我试图弄乱isUserInteractionEnabled方法无济于事。

In addition, I can sometimes get the "cell selected" message to print if I tap really fast but it is very seldom. 另外,如果我点击得非常快,有时我可以得到"cell selected"消息以打印,但很少。 Let me know if you have any suggestions! 如果您有任何建议,请告诉我!

func drawCircle() {
    var circleLayer: CAShapeLayer!

    let arcCenter = CGPoint(x: frame.size.width / 2.0, y: (frame.size.height / 2.0) - 15)
    let circlePath = UIBezierPath(arcCenter: arcCenter, radius: (frame.size.width - 20) / 2, startAngle: 0.0, endAngle: CGFloat(.pi * 2.0), clockwise: true)

    circleLayer = CAShapeLayer()
    circleLayer.path = circlePath.cgPath
    circleLayer.fillColor = UIColor.clear.cgColor
    circleLayer.strokeColor = UIColor(named: "Fourth")?.cgColor
    circleLayer.lineWidth = 8.0

    circleLayer.strokeEnd = 1.0

    // Add the circleLayer to the view's layer's sublayers
    layer.addSublayer(circleLayer)
}

This was fixed by setting cancelsTouchesInView method to false on a UITapGestureRecognizer I have. 通过在我拥有的UITapGestureRecognizer cancelsTouchesInView方法设置为false可以解决此问题。 Full code below. 完整代码如下。

let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.hideKeyboardByTappingOutside))
    tap.cancelsTouchesInView = false
    self.view.addGestureRecognizer(tap)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 collectionView didSelectItemAt indexPath 未调用 swift - collectionView didSelectItemAt indexPath not called swift collectionView:UICollectionView,didSelectItemAt indexPath:未执行IndexPath - collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath is not executed CollectionView didSelectItemAt 没有被调用 - CollectionView didSelectItemAt is not getting called CollectionView 方法 cellForItemAt indexPath:未被调用(Swift) - CollectionView method cellForItemAt indexPath: not being called (Swift) didSelectItem没有被调用 - didSelectItemAt not being called UICollectionView didSelectItemAt 未被调用 - UICollectionView didSelectItemAt not being called 长按后调用 didSelectItemAt indexPath - didSelectItemAt indexPath called after a long press collectionView函数didSelectItemAt indexPath将数据传递给下一个视图控制器 - collectionView function didSelectItemAt indexPath to pass data to next view controller 与UITapGestureRecognizer一起使用时,不调用collectionView的didSelectItemAt - collectionView's didSelectItemAt not called when use it with UITapGestureRecognizer collectionView(collectionView,didSelectItemAt:indexPath)-无法调用非函数类型'UICollectionView的值 - collectionView(collectionView, didSelectItemAt: indexPath) - Cannot call value of non-function type 'UICollectionView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM