簡體   English   中英

帶有手勢識別器的UICollectionView

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM