1

我的故事板上有一个 UIPageViewController,现在我想知道如何向它添加视图控制器?假设我有 5 个视图控制器,如何将它们从头到尾添加到 UIPageViewController?通常我会这样做:

        [self addChildViewController:firstViewController];
        [self addChildViewController:secondViewController];
        [self addChildViewController:thridViewController];
        [self addChildViewController:fourthViewController];
        [self addChildViewController:fifthViewController];

但我不知道如何按这个顺序在 UIPageViewController 上添加它......

编辑:

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");}];
4

1 回答 1

3

UIPageViewController 不允许以一种简单的方式一次添加一个新的视图控制器,大概是因为 Apple 希望开发人员不要轻易地一次添加一个页面(我可以看到这对于应用程序的用户来说是令人困惑的 UI)。

要做你想做的事,你必须将新的视图控制器添加到一个数组(大概是已经存在的视图控制器的数组,你通过" viewControllers"检索),然后用包括你的视图控制器的数组调用" setViewControllers:direction:animated:completion:"一个(或多个)要添加到页面视图控制器的新视图控制器。

于 2013-04-03T09:35:29.680 回答