Skip to content

Instantly share code, notes, and snippets.

@amster
Last active August 29, 2015 13:56
Show Gist options
  • Save amster/9201042 to your computer and use it in GitHub Desktop.
Save amster/9201042 to your computer and use it in GitHub Desktop.
// Assuming SomePageViewController has a property called idx that holds its page number.
// Some number
#define MAX_PAGES 5
// Factory method
- (UIViewController *)viewControllerAtIndex:(int)i {
// Asking for a page that is out of bounds??
if (i<0) {
return nil;
}
if (i>=MAX_PAGES) {
return nil;
}
// Assuming you have SomePageViewController.xib
SomePageViewController *newController = [[SomePageViewController alloc] initWithNibName:@"SomePageViewController" bundle:nil];
newController.idx = i;
return newController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
SomePageViewController *p = (SomePageViewController *)viewController;
return [self viewControllerAtIndex:(p.idx - 1)];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
SomePageViewController *p = (SomePageViewController *)viewController;
return [self viewControllerAtIndex:(p.idx + 1)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment