Irwan Madness
Irwan Madness

Reputation: 1396

How to select all and clear items/cells in UIButton action method

I have a UICollectionView and I try to select all or clear all item/cell after a UIButton is tapped.

How can I do that like picture?

enter link description here

Upvotes: 0

Views: 140

Answers (1)

Jaydeep Vora
Jaydeep Vora

Reputation: 6223

For that you have to manage one array for selection or you if you are using model then you can add one more field for selection property.

@IBAction func selectAll(_ sender: UIButton) {
  // Set Whole Array to 1 and reload collection view.
}

@IBAction func clearAll(_ sender: UIButton) {
  //Set Whole array to 0 and reload collection View
}


// In collectionView method Check selection condition and Display Check mark.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    // If Array value is 1 at indexPath.row then set Checked view otherwise Unchecked view.
  }

Upvotes: 1

Related Questions