Created
February 12, 2015 09:18
-
-
Save jkhowland/4d64fbb23c793b4fbd3e to your computer and use it in GitHub Desktop.
PageViewControllerDataSource
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
- (UIViewController *)initialViewController { | |
ContentViewController *viewController = [ContentViewController new]; | |
viewController.index = 0; | |
viewController.name = [[ContentController sharedInstance].content[0] description]; | |
return viewController; | |
} | |
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { | |
NSInteger beforeIndex = ((ContentViewController *)viewController).index - 1; | |
return [self viewControllerAtIndex:beforeIndex]; | |
} | |
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { | |
NSInteger afterIndex = ((ContentViewController *)viewController).index + 1; | |
return [self viewControllerAtIndex:afterIndex]; | |
} | |
- (UIViewController *)viewControllerAtIndex:(NSInteger)index { | |
// Returning nil is how the pageViewController knows it has reached the end of the paging. We need to see if the current index is 0 or if the index is beyond the content. | |
if (index < 0 || index >= [ContentController sharedInstance].content.count) { | |
return nil; | |
} | |
ContentViewController *viewController = [ContentViewController new]; | |
viewController.index = index; | |
viewController.name = [ContentController sharedInstance].content[index]; | |
return viewController; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment