UIPopoverController与UIPageViewController没有显示任何内容

时间:2012-05-26 22:07:50

标签: uipopovercontroller uipageviewcontroller

我尝试在弹出控制器的视图中显示不同视图控制器的视图。我现在尝试了三个小时但没有成功。基本上这就是我所做的:

- (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];
}

这就是我所看到的:

enter image description here

我在这里缺少什么?

1 个答案:

答案 0 :(得分:2)

好的,如果有人遇到类似的问题,我就解决了:

似乎在初始化之后你必须准确设置一次所需的视图控制器的数量

因此,如果您创建一次显示一页的UIPageViewController,请在setViewControllers:direction:animated:completion:中放置一个包含完全(!)一个视图控制器的数组。不止一个导致我的控制器什么也没显示。稍后可以通过实施UIPageViewControllerDelegateUIPageViewControllerDataSource协议来懒惰地添加其他视图控制器。