UIPageViewController - 不是从头开始,而是在中间(第2页)

时间:2016-10-06 10:49:49

标签: ios swift uipageviewcontroller

我已经设置了一个有三页的PageViewController。但是,我希望它从第2页开始(在中间)。但我不知道该怎么做。

我知道你设置了这样的开始viewController

pageViewController.setViewControllers([viewControllerAtIndex(startIndex)!], direction: .forward, animated: true, completion: nil)

但您只能说direction forwardreverse。但在这种情况下,两者都是。

我该怎么办?谢谢!

1 个答案:

答案 0 :(得分:2)

您对startViewController的实现是正确的

pageViewController.setViewControllers([viewControllerAtIndex(startIndex)!], direction: .forward, animated: false, completion: nil)

在您的UIPageViewControllerDataSource实现中,还要实现此方法:

func presentationIndex(for pageViewController: UIPageViewController) -> Int {
    return startIndex
}

您可能还需要

func presentationCount(for pageViewController: UIPageViewController) -> Int {
    return pageData.count
}