I try to show views of different view controllers within a popover controller's view. I tried for three hours now but without success. Basically this is what I've done:
- (IBAction)buttonTapped:(id)sender {
NSDictionary *options = [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey:UIPageViewControllerOptionSpineLocationKey];
UIPageViewController *pageVC = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:options];
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad"
bundle:[NSBundle mainBundle]];
UIViewController *firstVC = [sb instantiateViewControllerWithIdentifier:@"FirstTableViewController"];
UIViewController *secondVC = [sb instantiateViewControllerWithIdentifier:@"SecondViewController"];
NSArray *viewControllers = [[NSArray alloc] initWithObjects:firstVC, secondVC, nil];
[pageVC setViewControllers:viewControllers direction:UIPageViewControllerTransitionStylePageCurl animated:NO completion:nil];
UIButton *button = sender;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:pvc];
[popover presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
And this is what I get to see:
What am I missing here?
Ok, if someone encounters a similar problem, I solved it:
It seems that right after initialization you have to set exactly the number of view controllers that are needed at a time.
So, if you create a
UIPageViewController
with one page displayed at a time, put an array containing exactly(!) one view controller insetViewControllers:direction:animated:completion:
. More than one caused my controller to display nothing. Other view controllers can later be added lazily by implementing theUIPageViewControllerDelegate
andUIPageViewControllerDataSource
protocols.