2015-11-28 119 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