title: UICollectionView - Update Array indexPath based on Horizontal Scrolling
body: <p>Hi I m using two collection cell to display data, Child Collection view values are based on main Collection View.</p>
  
  <p>I have Video List and when i select Video In Table i m passing Complete array at index path, so that the main collection view will be displayed based on selected indexPath of array.</p>
  
  <p>it is displaying fine, but when i scroll it horizontal, I an passing visible cell indexPath data to fetch child collection View Data. </p>
  
  <p>But when i scroll Main Collection View , The array at indexPath is not updating based on Main Collection View it always display same IndexPath which is Passed From Video List(Previous View Controller).</p>
  
  <p>How to update main collection view array based on horizontal Scrolling.</p>
  
  <p>I want ion this scenario-</p>
  
  <p><strong>For example VIdeo list array is 1,2,3,4</strong></p>
  
  <p>i select 3 index and pass to collection view for videolist array, it displayed selected index path row value, when i scroll right side the index path should get increased to 4 on right and left it should decrease to 2, for any values selected on video list array. Main Collection view should work based on passed index path and act based on its index path</p>
  
  <p>My Code-</p>
  
  <pre><code>- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  {
   if(self.childCollectionView ==collectionView)
   {
      return [self.array_ChildElements count];
  }
  else
  {
      return [self.array_VideoList count];
  }
  }
  
  - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {
  if (collectionView ==self.collectionView)
  {
      VVCollectionCell *cell = (VVCollectionCell *)[self.collectionView dequeueReusableCellWithReuseIdentifier:@"VVCollectionCell" forIndexPath:indexPath];
  
      VVSystems *obj;
      if (self.iscalledFromVideoLIst)
      {
          obj =self.array_VideoList[self.selectedIndexPath.row];
  
      }
      else
      {
          obj =self.array_VideoList[indexPath.row];
      }
      [self.collectionView flashScrollIndicators];
  
      NSLog(@"Current Index Path---&gt;%ld",(long)self.selectedIndexPath.row);
      NSLog(@"Current Title---&gt;%@",obj.title);
  
      [cell.labelVideoTitle setText:obj.title];
      [cell.imgVideo sd_setImageWithURL:[NSURL URLWithString:obj.iconImage]
                       placeholderImage:nil];
  
      return cell;
  }
  else
  {
      childCollectionCell *cell2 = (childCollectionCell *)[self.childCollectionView dequeueReusableCellWithReuseIdentifier:@"childCollectionCell" forIndexPath:indexPath];
      ChildAnimations *obj = self.array_ChildElements[indexPath.row];
      [self.childCollectionView flashScrollIndicators];
  
      [cell2.labelTitel setText:obj.tagName];
      [cell2.imgbackGround sd_setImageWithURL:[NSURL URLWithString:obj.image]
                       placeholderImage:nil];
      return cell2;
  }
  }
  
  - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  {
  
  for (VVCollectionCell *cell in [self.collectionView visibleCells])
  {
      NSIndexPath *newIndexPath = [self.collectionView indexPathForCell:cell];
  
  
      VVSystems *objCustVehiclesList =self.array_VideoList[newIndexPath.row];
  
      NSLog(@"Current Index Path Row --&gt;%ld",(long)newIndexPath.row);
      NSLog(@"Current Title---&gt;%@",objCustVehiclesList.title);
  
  
      self.str_partID =objCustVehiclesList.partID;
      [self ServiceCallForChildVideo:self.str_partID];
      self.iscalledFromVideoLIst = NO;
  
  }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/QmCST.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QmCST.png" alt="enter image description here"></a></p>