具有多个viewControllers的pageController

时间:2015-12-28 23:18:19

标签: ios swift

我试图添加一个包含多个viewControllers的pagecontroller。我首先在interfacebuilder中创建了一个contentView并在其中嵌入了一个pageController。然后我添加了以下代码,但它似乎没有显示任何内容?

   let initialViewController = self.viewControllerAtIndex(0)
    self.pageViewController?.setViewControllers([initialViewController], direction: .Forward, animated: false, completion: nil)

PAgeViewController Extension

var viewControllerIdentifiers = ["BottomNoLogo", "TopNoLogo"]



extension CameraViewController: UIPageViewControllerDataSource {
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
    let currentText = viewController.restorationIdentifier

    var currentIndex = viewControllerIdentifiers.indexOf(currentText!)
    if currentIndex == viewControllerIdentifiers.count - 1 {
        return viewControllerAtIndex(0)
    } else {
        return viewControllerAtIndex(++currentIndex!)
    }
}

func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
    let currentText = viewController.restorationIdentifier

    var currentIndex = viewControllerIdentifiers.indexOf(currentText!)
    if currentIndex == 0 {
        return viewControllerAtIndex(viewControllerIdentifiers.count - 1)
    } else {
        return viewControllerAtIndex(--currentIndex!)
    }
}

func viewControllerAtIndex(index: Int) -> UIViewController {

    let contentViewController = storyboard?.instantiateViewControllerWithIdentifier(viewControllerIdentifiers[index])

    return contentViewController!
}


}

1 个答案:

答案 0 :(得分:-1)

页面视图控制器实际上只提供了点:您仍然需要将控制器的视图添加为父视图的子视图并管理滚动。那里有很多例子。例如,请参阅http://www.appcoda.com/uipageviewcontroller-tutorial-intro/