長押しジェスチャが添付された 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)")
}
}
}
}
}