Last active
August 29, 2015 13:56
-
-
Save amster/9201042 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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