mindsnacks / MSPageViewController

Create UIPageViewControllers using only storyboards
MIT License
89 stars 23 forks source link

Programatically select page #6

Closed jasoncox closed 10 years ago

jasoncox commented 10 years ago

Is it possible to programatically select a page from an MSPageViewControllerPage button? How would I go about doing that?

NachoSoto commented 10 years ago

The same way you would do it in a UIPageViewController.

hkwaller commented 10 years ago

For those of us who are stupid enough to not manage that, would you care to elaborate just a bit? I've been trying all sorts of things, but can't seem to wrap my head around it. No doubt it's my own fault, but I really can't get past it.

Thank you in advance.

jasoncox commented 10 years ago

@hkwaller first you need to add to your MSPageViewController:

#import "MSPageViewController+Protected.h"

You now have access to viewControllerAtIndex which will return you the view controller at index position set up by the page identifiers array.

Then all you need to do is call the following with the index you want to jump to:

[self setViewControllers:@[[self viewControllerAtIndex:2]] direction:
UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];

Hope that helps!