title: how to get indexpath value uiCollectionView iOS objective c
body: <p>hi I want to get the value of index path to get the data from array of the tapped cell how do I do that?</p>
  
  <p>below Is my collection view method the self.iname is array that contains name and cat is category id I have to send the selected image category id to next page I am not able to extract it</p>
  
  <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  
  {
  
  
  ColCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  
  
  if(self.iname!=0){
  
      [cell setTag:indexPath.row];    // set tag to the indexPath.row so we can access it later
  
  //     add interactivity
      UITapGestureRecognizer * tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onButtonTapped:)];
  
  [tap setNumberOfTapsRequired:1];
  
     [cell addGestureRecognizer:tap];
   //   UITapGestureRecognizer *frameTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(frameTapGesture:)];
     // [cell.dimg addGestureRecognizer:frameTapGesture];
  
      NSString *fileName = [NSString stringWithFormat:@"%@",self.iname]; //objectAtIndex:indexPath];
  
      NSLog(@"%@",fileName);
  
      NSString *baseurl=[NSString stringWithFormat:@"http://test.kre8tives.com/barebon/upload/"];
  
      NSDictionary *dict = self.iname[indexPath.row];
  
      NSLog(@"%@", [self.iname objectAtIndex: indexPath.row]);
  
      NSString *paths = [NSString stringWithFormat:@"%@%@", baseurl, dict];
  
      NSLog(@"@@@@%@",paths);
  
      [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:paths]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  
          NSLog(@"%@",response);
  
  
          UIImage *imgage = [[UIImage alloc] initWithData:data];
          UIImageView *dimg = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,100,100)];
          dimg.clipsToBounds = YES;
          [cell.dimg setImage:imgage];
  
  
          if(cell.dimg==!nil)
          {
              NSLog(@"Not nil");
          }
          else{
              NSLog(@"nil");
          }
          if(cell.lbl==!nil)
          {
              NSLog(@"Not nil");
          }
          else{
              NSLog(@"nil");
          }
  
          cell.dimg.image=imgage;
          cell.lbl.text=[self.tempz objectAtIndex:indexPath.row];
          NSLog(@"%@",[self.iname objectAtIndex:indexPath.row]);
  
      }];
  }
  if(cell)
  {
     // self.catid=[self.categoryid objectAtIndex:indexPath.row];
      //NSLog(@"%@",self.catid);
  }
  //if (cell.selected) {
   //   cell.backgroundColor = [UIColor blueColor]; // highlight selection
   // }
   // else
   // {
       // cell.backgroundColor = [UIColor redColor]; // Default color
   // }
    return cell;
  }
  </code></pre>
  
  <p>this is my tap gesture method</p>
  
  <pre><code>- (void)onButtonTapped:(UITapGestureRecognizer *)gestureRecognizer {
    //UIImageView *myImage = (UIImageView *)gestureRecognizer.view;
  //    do stuff;
    self.catid=self.categoryid;
  
    NSLog(@"%@",self.catid);
     CGPoint tapPoint = [gestureRecognizer locationInView:gestureRecognizer.view];
    UIView *tappedView = [gestureRecognizer.view hitTest:tapPoint withEvent:nil];
  
    if ([tappedView isKindOfClass:[UILabel class]]) {
        NSLog(@"Found");
      }
     [self performSegueWithIdentifier:@"d2" sender:self];
    NSLog(@"it works");
   }
  </code></pre>