[英]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.