title: iOS: ScrollView infinite paging - Duplicate end caps
body: <p>I have a question about infinite paging in a ScrollView. In my app I have only 3 subviews in ScrollView. Each subview is loaded from xib file. Normally it looks like ABC in ScrollView. I wanted to make infinite paging so I added end caps and now it looks like CABCA. If the user is on the first C, it jumps to regular C and if user is on the last A, it jumps to regular A. Here is a code:</p>
  
  <pre><code>- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender {
  
    if (scrollView.contentOffset.x == 0)
    {
        [scrollView scrollRectToVisible:CGRectMake
        ((scrollView.frame.size.width * 3), 0,
        scrollView.frame.size.width,
        scrollView.frame.size.height) animated:NO];
    } 
    else if (scrollView.contentOffset.x == scrollView.frame.size.width * 4)
    {
       [scrollView scrollRectToVisible:CGRectMake
       (scrollView.frame.size.width, 0,
        scrollView.frame.size.width,
        scrollView.frame.size.height) animated:NO];
     }
  }
  </code></pre>
  
  <p>It works perfectly now. But I have ViewController for each subview and this is how I am adding them to ScrollView:</p>
  
  <pre><code>  subViewController1 = [[SubViewController1 alloc] initWithNibName:@"SubView" bundle:nil];
    subViewController1.view.frame =
      CGRectMake(0, 0, scrollView.frame.size.width, scrollView.frame.size.height);
    [scrollView addSubview:subViewController1.view];
  </code></pre>
  
  <p>Problem is that there is one duplicate of A and C view so now I have 5 controllers instead of 3. And If I want to add something into a A view, I have to add it also into duplicate of A view. </p>
  
  <p>Is there a way how to control view A and duplicate of A with one controller so I don't have to create two instances of one controller? Thank you.</p>