選択状態の設定
.m
// 複数選択する場合はallowsMultipleSelectionをYESに設定する
_collectionView.allowsMultipleSelection = YES;
// 一番最初のCellを選択する
NSIndexPath *selectIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[_collectionView selectItemAtIndexPath:selectIndexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
選択状態の解除
複数選択の場合
.m
// 選択されているIndexPathを全て非選択状態にする
for (NSIndexPath *indexPath in _collectionView.indexPathsForSelectedItems) {
[_collectionView deselectItemAtIndexPath:indexPath animated:NO];
}
単一選択の場合
.m
[_collectionView deselectItemAtIndexPath:[_collectionView.indexPathsForSelectedItems lastObject] animated:NO];