2015-10-13 49 views
-1

我試圖做一個集合視圖,除了當我嘗試選擇一個單元格時,一切都在工作。UICollectionViewCell didDeselectItemAtIndexPath不叫

我的方法didDeselectItemAtIndexPath未被調用。

在主故事板中,我有一個嵌入導航視圖控制器的collectionviewcell控制器。 collectionviewC調用另一個控制器打印詳細信息,其中兩個之間有一個叫做segueDetailFeature 的segue,我有另一個項目,我確實喜歡那個,它的工作方式是tableviewcontroller

圖像顯示效果良好,數字菲林中的打印效果很好。

這裏是我的控制器代碼:



class ViewController: UICollectionViewController { 


    var listImageUrl = [String]() 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // code to populate the listImageUrl 

     self.collectionView?.delegate = self 
     self.collectionView?.dataSource = self 
    } 

    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     print("nombre d'image : \(listImageUrl.count)") 
     return listImageUrl.count 
    } 

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as UICollectionViewCell 

     let imageView = cell.viewWithTag(1) as! UIImageView 
     let urlString: NSString = listImageUrl[indexPath.row] as NSString 
     let imgURL: NSURL = NSURL(string: urlString as String)! 

     //Télécharger une représentation NSData de l'image à cette URL 
     let imgData: NSData = NSData(contentsOfURL: imgURL)! 
     imageView.image = UIImage(data: imgData) 

     //imageView.image = UIImage(named: listImageUrl[indexPath.row]) 

     return cell 
    } 

    override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) { 
     print("selected item at index") 
     let urlImage = listImageUrl[indexPath.row] 
     imageUri = urlImage 
     performSegueWithIdentifier("segueDetailFeature", sender: collectionView) 
    } 


} 

我找不到爲什麼我的代碼不工作,爲什麼我的didDeselectItemAtIndexPath不叫。然而,當我運行它時,應用程序使用segue並加載細節控制器,但它失敗了,因爲一個變量沒有在方法select中被實例化。

在此先感謝

+0

你是不是要實現'didSelect'而不是'didDeselect'? – matt

+0

我覺得我很笨。事實上,我沒有看到它被取消選擇,他們的方法的名稱是這麼長,它沒有發生在我身上,我會讓你知道它的工作原理:-) thx! –

+0

我在20%的時間裏犯了這個錯誤,只是偶爾不能吸取教訓。 – danh

回答

相關問題