Created
February 25, 2014 01:57
-
-
Save amster/9201207 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 property UIPageViewController *pager. | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Create it. | |
self.pager = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; | |
// Point the datasource back to this UIViewController. | |
self.pager.dataSource = self; | |
// Start at the first page of the array? | |
int initialIndex = 0; | |
// Assuming you have a SomePageViewController which extends UIViewController so you can do custom things. | |
SomePageViewController *initialViewController = (SomePageViewController *)[self viewControllerAtIndex:initialIndex]; | |
NSArray *initialViewControllers = [NSArray arrayWithObject:initialViewController]; | |
// animated:NO is important so the view just pops into existence. | |
// direction: doesn't matter because it's not animating in. | |
[self.pager setViewControllers:initialViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; | |
// Tell the child view to get ready | |
[self.pager willMoveToParentViewController:self]; | |
// Actually add the child view controller | |
[self addChildViewController:self.pager]; | |
// Don't forget to add the new root view to the current view hierarchy! | |
[self.view addSubview:self.pager.view]; | |
// And make sure to activate! | |
[self.pager didMoveToParentViewController:self]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment