GETTING NUMBER OF ITEMS SELECTED IN UICOLLECTIONVIEW IN IOS.

Sanjay Sharma

Total Post:45

Points:315
Posted by  Sanjay Sharma
 668  View(s)
Ratings:
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.

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: Getting number of Items selected in UICollectionView in iOS.

    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

Answer

NEWSLETTER

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