Search code examples
iosobjective-ciphoneios7

How to get position of view created programmatically in scrollview placed in cell and cell indexpath in tableview in iOS


This is my code:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

 CGFloat pageWidth = scrollView.frame.size.width;

 int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

 NSLog(@"Page No Scroll %i",page);

}

Solution

  • -(void)scrollViewDidScroll:(UIScrollView *)ScrollView
    {
    int scrollPositionX = callerScrollView.contentOffset.x;
    if (callerScrollView == tbl_ProductView) return;
     for (UITableViewCell *cell in tbl_ProductView.visibleCells) {
    UIScrollView cellScrollView = (UIScrollView )[cell viewWithTag:100];
    if (callerScrollView == cellScrollView) continue;
    NSInteger indexPath = callerScrollView.tag;
    //NSLog(@"IndexPath Of Cell: %ld",(long)indexPath);
    cellScrollView.contentOffset = CGPointMake(scrollPositionX, 0);
    }
    //ScollPage Position
    static NSInteger previousPage = 0;
    CGFloat pageWidth = callerScrollView.frame.size.width;
    float fractionalPage = callerScrollView.contentOffset.x / pageWidth;
     NSInteger page = lround(fractionalPage);
      if (previousPage != page)
     {
       previousPage = page;
        NSLog(@"Scrolling Page: %li",(long)page);
     }
    }