![](/img/trans.png)
[英]Long press tap gesture recogniser for UICollectionView Objective-c
[英]UICollectionView with gesture recogniser
我有一个UICollectionView带有长按手势。 当我按一个单元格时它可以正常工作,但是如果触摸的区域不是一个单元格,则应用程序会崩溃并显示EXC_BREAKPOINT
它崩溃了
if let indexPath : NSIndexPath = collectView.indexPathForItemAtPoint(point)! {
线。 我相信我需要检查该点实际上是一个单元格,但是我不确定要检查什么
代码如下
@IBAction func longPressCell(sender: UILongPressGestureRecognizer) {
if (sender.state == UIGestureRecognizerState.Began) {
if let point : CGPoint = sender.locationInView(self.collectionView) {
if let collectView = self.collectionView {
if let indexPath : NSIndexPath = collectView.indexPathForItemAtPoint(point)! {
let adopt : UserPet = self.fetchedResultsController.objectAtIndexPath(indexPath) as! UserPet
NSLog("Adopt: \(adopt)")
}
}
}
}
}
collectView.indexPathForItemAtPoint(point)!= nil {已解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.