I'm trying to select all UICollectionViewCells after a UIButton is tapped.
How do I do this?
Updated for Swift 3
Just Shadow's Answer updated to Swift 3
for i in 0..<assetCollectionView.numberOfSections {
for j in 0..<assetCollectionView.numberOfItems(inSection: i) {
assetCollectionView.selectItem(atIndexPath: IndexPath(row: j, section: i), animated: false, scrollPosition: .none)
}
}
You can select all cells in the first section through:
for (NSInteger row = 0; row < [self.collectionView numberOfItemsInSection:0]; row++) {
[self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] animated:NO scrollPosition:UICollectionViewScrollPositionNone];
}
If you have more than 1 section, just use another nested for loop to loop through all the sections.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With