Skip to content

Instantly share code, notes, and snippets.

@amster
Created February 25, 2014 01:57
Show Gist options
  • Save amster/9201207 to your computer and use it in GitHub Desktop.
Save amster/9201207 to your computer and use it in GitHub Desktop.
// 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