HOW TO ALLOW MULTIPLE SELECTION IN UICOLLECTIONVIEW IN IOS?

Steven Hill

Total Post:10

Points:72
Posted by  Steven Hill
 3672  View(s)
Ratings:
Rate this:

I am create an application like Photo album in iPhone.
Can any one tell me that how can I add functionality for multiple selection for specific section in UICollectionView?
I am using this code:

[self.collectionView setAllowsMultipleSelection:YES];

but, the above code will affects all sections.
Please suggest me any solution?

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: How to allow multiple selection in UICollectionView in iOS?

    The code I am providing here it will allow multiple selection only at section 1 and will allow only one cell selected at any other section:
    For Example:

    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
        if(indexPath.section == 1) return;
        NSArray<NSIndexPath*>* indexNo = collectionView.indexPathsForSelectedItems;
        for (int i = 0; i<indexNo.count; i++) {
            NSIndexPath* currentIndex = indexNo[i];
            if(![currentIndex isEqual:indexPath] && currentIndex.section != 1) {
                [collectionView deselectItemAtIndexPath:currentIndex animated:YES];
            }
        }
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!