Reputation: 491
I got a UIPageViewController on my storyboard, and now I'm wondering how do I add a view controller to it? Lets say if I got 5 view controllers, how do I add those from the beginning to the end to the UIPageViewController? Normally I would do this:
[self addChildViewController:firstViewController];
[self addChildViewController:secondViewController];
[self addChildViewController:thridViewController];
[self addChildViewController:fourthViewController];
[self addChildViewController:fifthViewController];
But I'm not sure how to add this on the UIPageViewController in this order...
EDIT:
ChapterViewController *chapterViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ChapterView"];
NSArray *viewControllers = [NSArray arrayWithObject:chapterViewController];
[self setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:^(BOOL finished){
NSLog(@"call back success");}];
Upvotes: 1
Views: 3628
Reputation: 89509
UIPageViewController doesn't allow an easy way to add new view controllers one at a time, presumably because Apple wants developers to not add pages one at a time very easily (I could see this being confusing UI for users of an app).
To do what you want to do, you have to add the new view controller to an array (presumably the array of already existing view controllers, which you retrieve via "viewControllers
") and then call "setViewControllers:direction:animated:completion:
" with the new array of view controllers including your one (or more) new view controllers to be added to the Page View Controller.
Upvotes: 3