2016-07-08 32 views
1

我想選擇全部並取消選擇collectionView的所有單元格使用全部選擇並全部取消選擇UIButton? 請幫助任何人。我有UICollectionViewCell中的複選框圖像,我想顯示爲選定或未選中?

//Delegate Method cellForItemAtIndexPath 
func collectionView(collectionView: UICollectionView, 
cellForItemAtIndexPath indexPath: NSIndexPath) -> 
UICollectionViewCell 
{ 
    //Get a reference to our storyboard cell 
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(
                  "pickSomecell", 
        forIndexPath: indexPath) as!  pickSomeGridViewController 
    //Show Images in grid view 
    cell.cellImage.image = self.arrAllOriginalImages[indexPath.row] as? UIImage 
    cell.toggleSelected() 

    //return cell. 
    return cell 
} 

感謝

+0

你的意思是你有UICollectionViewCell要作爲選擇或取消選擇顯示覆選框圖像? –

+0

是@BhumitMehta 但我想一起選擇所有圖像。 – kishor

+0

你可以在CellForItemAtIndexPath中發佈你的代碼嗎? –

回答

1

嘗試做的後續

var isSelectAll=false 


    func collectionView(collectionView: UICollectionView, 
         cellForItemAtIndexPath indexPath: NSIndexPath) -> 
     UICollectionViewCell 
    { 
     //Get a reference to our storyboard cell 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier(
      "pickSomecell", 
      forIndexPath: indexPath) 
     //Show Images in grid view 

     if isSelectAll { 

      cell.cellImage.image = selectedImage; 
     }else{ 
      cell.cellImage.image = desselectedImage; 
     } 


     return cell 
    } 

@IBAction func selectAllcell(sender: AnyObject) { 

    isSelectAll=true 
    collectionView.reloadData() 

} 

@IBAction func deselectAllcell(sender: AnyObject) { 

    isSelectAll=false 
    collectionView.reloadData() 

} 
+0

好吧,讓我試試。 非常感謝。 – kishor

相關問題