title: PageViewController delegate functions called twice
body: <p>I am working with UIPageViewController , to make a product tour for my application.</p>
  
  <p>I followed this link <a href="http://www.appcoda.com/uipageviewcontroller-tutorial-intro/">http://www.appcoda.com/uipageviewcontroller-tutorial-intro/</a></p>
  
  <p>I am doing is simple task of changing backgound color of my <strong>"root VC"</strong> on swipe, based on the index value I get, but as the delegate functions are called twice, my index value is not correct and because of that, I am not able to get it right, below is my code</p>
  
  <pre><code>#import "APPViewController.h"
  #import "APPChildViewController.h"
  
  @interface APPViewController ()
  
  @end
  
  @implementation APPViewController
  
  - (void)viewDidLoad {
  
      [super viewDidLoad];
  
      self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
  
      self.pageController.dataSource = self;
      [[self.pageController view] setFrame:CGRectMake(0, 0, 320, 500)];
  
      APPChildViewController *initialViewController = [self viewControllerAtIndex:0];
  
      NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
  
      [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
  
      [self addChildViewController:self.pageController];
      [[self view] addSubview:[self.pageController view]];
      [self.pageController didMoveToParentViewController:self];
  
  }
  
  - (void)didReceiveMemoryWarning {
  
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  
  }
  
  - (APPChildViewController *)viewControllerAtIndex:(NSUInteger)index {
  
      APPChildViewController *childViewController = [[APPChildViewController alloc] initWithNibName:@"APPChildViewController" bundle:nil];
      childViewController.index = index;
      childViewController.view.backgroundColor = [UIColor clearColor];
  
      if(index == 0)
      {
            self.view.backgroundColor = [UIColor redColor];
       }
  
      if(index == 1)
      {
            self.view.backgroundColor = [UIColor blueColor];
       }
  
      if(index == 2)
      {
            self.view.backgroundColor = [UIColor greenColor];
       }
  
  
      return childViewController;
  
  }
  
  - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
  
      NSUInteger index = [(APPChildViewController *)viewController index];
  
      if (index == 0) {
          return nil;
      }
  
      // Decrease the index by 1 to return
      index--;
  
     return [self viewControllerAtIndex:index];
  
  }
  
  - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
  
      NSUInteger index = [(APPChildViewController *)viewController index];
  
      index++;
  
      if (index == 3) {
          return nil;
      }
  
     return [self viewControllerAtIndex:index];
  
  }
  
  - (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
      // The number of items reflected in the page indicator.
      return 3;
  }
  
  - (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
      // The selected item reflected in the page indicator.
      return 0;
  }
  </code></pre>
  
  <p>Please help me out, I am not getting where I am going wrong</p>
  
  <p>Regards
  Ranjit</p>