I have a functional tutorial intro implemented into my app, but i just can't seem to get the page view to pop off when i swipe the screen for the last time. I thought dismissViewControllerAnimated:completion: would work
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = ((PageContentViewController*) viewController).pageIndex;
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.pageTitles count]) {
[self.pageViewController dismissViewControllerAnimated:YES completion:nil];
}
return [self viewControllerAtIndex:index];
}
I figured out how to get it to go away, but it goes away right when it gets to the last page. I want it to show the last page and then go away when the user swipes right again on that last page.
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = ((PageContentViewController*) viewController).pageIndex;
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.pageTitles count]) {
[self.pageViewController.view removeFromSuperview];
}
return [self viewControllerAtIndex:index];
}
Page View Controller is your main viewcontrollers child view controller, this is the correct way to remove childViewController:
Also encountered the same issue and my solution was to add an extra page that was clear with the following code:
didFinishAnimating
is called beforeviewControllerAfter
. This means the value forcurrentIndex
will be for the previous page whendidFinishAnimating
is called. Hence why I subtract 2 (instead of 1)