Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I dismiss/pop a UIPageViewController after the last view controller is swiped?

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];
}
like image 838
ebi Avatar asked Jan 23 '14 17:01

ebi


1 Answers

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];
    }
}
like image 144
derpoliuk Avatar answered Sep 25 '22 18:09

derpoliuk