I have two controllers in our iPhone application. In one controller I have create a ImageCollection class and an NSMutableArrayimgArray. after that I have stored ImageCollection objects into the imgArray. Now, I want to get the specific index of ImageCollection object which is stored in the imgArray.
Can anyone tell me how can I find the index of any specific object. Please provide me some code if possible as hint for me.
Thank You.
How to get class object index in NSMutableArray in Xcode?
182323-Jan-2016
Updated on 23-Jan-2016
Tarun Kumar
23-Jan-2016To get the index of object from the mutable array. For that- first of all import the FirstViewController (where you create ImageCollection class and array) in the SecondViewController and under the @interface create a property of NSIndexPath. like this:
Now, go to the FirstViewController's implementation file import the SecondViewController. now, under the didSelectItemAtIndexPath: method of CollectionView create a reference of second view controller using storyboard like this:
now, when ever any collection view cell will be clicked, collection view method didSelectItemAtIndexPath: will be called which has the indexPath. Now we will assign it in the second view controller property indexPathOfImage, like this:
Now, we can use it in the second view controller to get the index from imgArray, like this:
that's it. I hope it will be helpful for you.