UIPage control indicator not working fully

I have a UIPageViewController setup. I am using a UIPage Control that I have added to the root view controller in the interface builder and added the outlet. I’m doing this so the UIPage control can be brought to the front of the views and remain transparent.

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{


    NSString *vcRestorationID = viewController.restorationIdentifier;
    NSUInteger index = [self.controllerRestorationIDs indexOfObject:vcRestorationID];
    if (index == 0) {
        return nil;
    }
    [self.pageControl setCurrentPage:index-1];
    return [self viewControllerAtIndex:index - 1];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    NSString *vcRestorationID = viewController.restorationIdentifier;
    NSUInteger index = [self.controllerRestorationIDs indexOfObject:vcRestorationID];

    //Don't allow it to go forward if there is one at the end
    if (index == self.controllerRestorationIDs.count - 1) {
        return nil;
    }

    [self.pageControl setCurrentPage:index+1];
    return [self viewControllerAtIndex:index + 1];
}

My code above sends the pageControl the index of the page. It works when moving forward one page and the indicator changes but when I move back it remains on the second page. Could anyone give me some pointers to why this might be happening? Thanks


Source: ios

Leave a Reply