How can I dismiss/pop a UIPageViewController after the last view controller is swiped? Basically want to make a tutorial style paging view with images, and to dismiss after the user swipes to the "next" page from the last.
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [(EmailTutorialViewController *)viewController index];
index++;
if (index == 5) {
[self.navigationController popViewControllerAnimated:YES]; // this doesn't do anything
return nil;
}
return [self viewControllerAtIndex:index];
}
Here's simple solution I've used:
In
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController;
return empty controller for index == 5
and add this UIPageViewControllerDelegate
method:
- (void)pageViewController:(UIPageViewController *)pageViewController
willTransitionToViewControllers:(NSArray *)pendingViewControllers
{
EmailTutorialViewController *viewController =
[pendingViewControllers objectAtIndex:0];
if ([viewController index] == 5)
{
[self.navigationController popViewControllerAnimated:YES];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With