UIPageViewController 和不同的视图控制器

UIPageViewController and different view controllers

我正在尝试实施 UIPageViewController。我以前做过,但在分页时使用相同的 UIViewController 并更改图像等。我现在想在不同 UIViewController 之间翻页。我正在尝试根据包含 UIViewControllers 的故事板 ID 的数组中的内容编写创建 UIViewController 的方法。例如我有这个数组:

self.controllerIdentifiers=[NSArray arrayWithObjects:@"ViewControllerTypeA",@"ViewControllerTypeB", nil];

正在努力实施:

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    if (self.controllerIndex==0) return nil;

    self.controllerIndex--;
    NSString *id = self.controllerIdentifiers[self.controllerIndex];

    //If I knew the controller type I would do something like this..

    ViewControllerTypeA *typeA = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerTypeA"];

    return typeA;
}

问题是我不确定如何告诉代码 UIViewController 是什么类型。我是否需要为每个可能的索引添加一些逻辑并以这种方式启动 UIViewController

我用this template来实现这个。 它来自一个(可能重复的)问题,您可以找到两个有趣的答案 there

编辑:
TL;DR 这个想法是使用故事板标识符为不同的视图控制器在需要时实例化它们,使用 PageViewControllerDataSource 协议方法。