Home > DeveloperSection > Forums > Getting number of Items selected in UICollectionView in iOS.
Sanjay Sharma
Sanjay Sharma

Total Post:45

Posted on    December-30-2015 7:27 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 584  View(s)
Rate this:

I have created an iPhone application using UICollectionView. I am using nsmutable array to count multi-selected Items in our collection view. I am using a lot of code only for counting.

Can anyone tell me how can I get the total number of Items selected in shortest and easiest way.

Tarun Kumar

Total Post:214

Posted on    December-30-2015 11:10 PM

Collection view provides a method indexPathsForSelectedItems: , this method helps in counting the total number of Items selected in current collection view controller.
but for doing it, it is necessary to allow collection view as multiple selection to true in the collection view method cellForItemAtIndexPath: , like this:

collectionView.allowsMultipleSelection = true;

now, to count no of selected Items in collection view use code like this (here I am using it in NSLog()) :

NSLog(@"NoOfSelectedItems:%d",[collectionView.indexPathsForSelectedItems count]);

Modified On Dec-30-2015 11:11:06 PM

Don't want to miss updates? Please click the below button!

Follow MindStick