---
title: "Getting cell index number of Collection view from out side the delegate methods in iOS."  
description: "Getting cell index number of Collection view from out side the delegate methods in iOS."  
author: "Tarun Kumar"  
published: 2016-01-01  
updated: 2016-01-01  
canonical: https://www.mindstick.com/forum/33819/getting-cell-index-number-of-collection-view-from-out-side-the-delegate-methods-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# Getting cell index number of Collection view from out side the delegate methods in iOS.

I want to find the touched cell [index](https://www.mindstick.com/blog/198/index-in-sql-server) number in [collection](https://www.mindstick.com/articles/1718/collections-in-java) [view controller](https://www.mindstick.com/forum/33709/how-to-use-table-view-controller-with-small-sized-in-ios) from out side its [delegate](https://www.mindstick.com/articles/777/delegate-and-event-in-c-sharp) methods. I want to create a [method](https://www.mindstick.com/forum/166/webservice-method) which helps me to find out the index no. but my [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is how can I find the cell index.

If is this possible then please provide [me the code](https://www.mindstick.com/forum/156831/can-you-tell-me-the-code-to-write-a-c-sharp-program) also.

Thank you.

## Replies

### Reply by Anonymous User

Yes, you can get the cell index no. with the help of **UITapGestureRecognizer.** You need to add the gesture recognizer on the cell [view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view). Use gesture recognizer like this:

```
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didImageSelect:)];recognizer.delegate = self;recognizer.numberOfTapsRequired=1;[cellImage addGestureRecognizer:recognizer];
```

above [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) we are adding gesture recognizer on cellImage reference. here cellImage is the reference of UIImageView which will be added on the cell view. and also we are using **didImageSelect:** method on the @selector.\
now, here is the **@selector didImageSelect:** method code which will be responsible for getting cell index:

```
-(void)didImageSelect:(UITapGestureRecognizer*)recognizer{  CGPoint *point = [recognizer locationInView:_collectionView];  NSIndexPath *indexPath = [_collectionView indexPathForItemAtPoint:point];  NSLog(@"IndexPath:%d",[indexPath row]);}
```

now, we get the cell index on the click on any cell in collection view on the **indexPath** variable.


---

Original Source: https://www.mindstick.com/forum/33819/getting-cell-index-number-of-collection-view-from-out-side-the-delegate-methods-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
