To use UIPageViewController effectively you would need an UIPageViewControllerDataSource, this will help to display the before and after UIViewController. Here is an simple implementation to get you started:
1 2 3 4 5 | #import <UIKit/UIKit.h> @interface PYPageViewController : UIPageViewController @property NSMutableArray *pages; @end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #import "PYPageViewController.h" @interface PYPageViewController() @end @implementation PYPageViewController @synthesize pages; - ( void )viewWillAppear:( BOOL )animated { [self setDataSource:(id)self]; //Use this class as the data source self.pages = [[NSMutableArray alloc]initWithCapacity:3]; [self.pages addObject:[self.storyboard instantiateViewControllerWithIdentifier:@ "PYRootViewController" ]]; [self.pages addObject:[self.storyboard instantiateViewControllerWithIdentifier:@ "PYNextViewController" ]]; [self.pages addObject:[self.storyboard instantiateViewControllerWithIdentifier:@ "PYEndViewController" ]]; [self setViewControllers:[NSArray arrayWithObject:pages[0]] direction:UIPageViewControllerNavigationDirectionForward animated: true completion:nil]; [super viewWillAppear:animated]; } /* UIPageViewControllerDataSource */ - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { UIViewController *view = nil; if ([self.pages objectAtIndex:0] != viewController){ for (NSUInteger i = [self.pages count]-1;i > 0 ; i--) { if ([self.pages objectAtIndex:i] == viewController){ view = [self.pages objectAtIndex:i-1]; break ; } } } return view; } - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { UIViewController * view = nil; if ([self.pages objectAtIndex:[self.pages count]-1] != viewController){ for (NSUInteger i = 0;i < [self.pages count]-1; i++) { if ([self.pages objectAtIndex:i] == viewController){ view = [self.pages objectAtIndex:i+1]; break ; } } } return view; } @end |