2015-11-28 63 views
0

我希望每個CollectionViewCell都能顯示圖像並隱藏標籤,如果它被點擊。但是,如果用戶滾動圖像突然顯示在其他沒有被觸及的地方。我如何識別某些細胞?識別唯一的CollectionViewCells

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { 

    println("user tapped on door number \(indexPath.row)") 

    let cell = collectionView.cellForItemAtIndexPath(indexPath) as! MyCollectionViewCell 

    if (cell.myLabel.text == "1") { 
     one = true 

      if (cell.myLabel.hidden) { 
       cell.myLabel.hidden = false 
       cell.MyImageView.image = nil 

      } 
      else { 
       cell.myLabel.hidden = true 
       cell.MyImageView.image = UIImage(named:"1")! 
      } 
    } 

回答

0

這是因爲細胞被重新使用的變化,從而代替每個小區,即被竊聽的小區的索引處改變的數據源。

+0

你能舉個例子嗎? – maidi