0

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

    }
}
4

1 に答える 1

0

collectView.indexPathForItemAtPoint(point) != nil { 解決しました

于 2016-05-23T10:47:09.067 に答える