How to add desclecting to a UICollectionView, but without multiple selection?

I currently have 4 different views in the view, and I want to allow undo. To do this, I must install:

//Stop multiple selections on collectionview
self.bagsCollectionView.allowsMultipleSelection = YES;
self.shoesCollectionView.allowsMultipleSelection = YES;
self.dressesCollectionView.allowsMultipleSelection = YES;
self.jewelleryCollectionView.allowsMultipleSelection = YES;

However, I only want to select one cell from each collector view. For example, in bagsCollectionView, the user can select one bag, but can also deselect and select a different package. They cannot choose two bags or two shoes. The same goes for the other three kinds of collections!

How to do it?

+4
source share
1 answer

( ), allowsMultipleSelection . . , , .

, ( ), ( ), - ( ). ( ) , , .

, , , , , UX. , , . ( ).

, , , , .

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *indexPaths = collectionView.indexPathsForSelectedItems;
    // Don't deselect our own index path
    [indexPaths removeObject:indexPath];
    for (NSIndexPath *otherIndexPath in indexPaths) {
        [collectionView deselectItemAtIndexPath:otherIndexPath animated:YES];
    }
    // ... Do whatever else you need to do in response to the selection
}
+14

Source: https://habr.com/ru/post/1627173/


All Articles