kishor kishor - 4 months ago 40
iOS Question

I have checkbox image in UICollectionViewCell which I want to show as selected or unselected?

I want to select all and deselect all cell of

collectionView
using select All and deselect all
UIButton
?
Please help anyone.

//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
}


Thanks

Answer

try to do as follow-

 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()

}