UIPopoverController with UIPageViewController show

2019-08-12 17:17发布

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:

enter image description here

What am I missing here?

1条回答
淡お忘
2楼-- · 2019-08-12 17:29

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 in setViewControllers:direction:animated:completion:. More than one caused my controller to display nothing. Other view controllers can later be added lazily by implementing the UIPageViewControllerDelegate and UIPageViewControllerDataSource protocols.

查看更多
登录 后发表回答