UIPageViewController不更新ViewControllers

时间:2017-05-15 13:35:44

标签: ios swift3 uipageviewcontroller

我正在尝试使用UIPageViewController,并在调试中考虑了幻灯片,但页面没有更新:

import UIKit

class TutorialPageViewController: UIPageViewController {

private(set) lazy var orderedViewControllers: [UIViewController] = {
    return [UINib(nibName: "FinansicalTradingViewController", bundle:nil).instantiate(withOwner: self, options: nil)[0] as? FinansicalTradingViewController,
            UINib(nibName: "VideoViewController", bundle:nil).instantiate(withOwner: self, options: nil)[0] as? VideoViewController,
            UINib(nibName: "AllowZeroViewController", bundle:nil).instantiate(withOwner: self, options: nil)[0] as? AllowZeroViewController,
            UINib(nibName: "TutorialStartViewController", bundle:nil).instantiate(withOwner: self, options: nil)[0] as? TutorialStartViewController]
    }() as! [UIViewController]


override func viewDidLoad() {
    super.viewDidLoad()

    dataSource = self

    //        let vc = UINib(nibName: "VideoViewController", bundle:nil).instantiate(withOwner: self, options: nil)[0] as? VideoViewController
    //        setViewControllers([vc!], direction: .forward, animated: true, completion: nil)

    if let firstViewController = orderedViewControllers.first {
        setViewControllers([firstViewController],
                           direction: .forward,
                           animated: true,
                           completion: nil)
    }

  }

}
extension TutorialPageViewController: UIPageViewControllerDataSource {

func pageViewController(_ pageViewController: UIPageViewController,
                        viewControllerBefore viewController: UIViewController) -> UIViewController? {
    guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
        return nil
    }

    let previousIndex = viewControllerIndex - 1

    guard previousIndex >= 0 else {
        return nil
    }

    guard orderedViewControllers.count > previousIndex else {
        return nil
    }

    return orderedViewControllers[previousIndex]
}

func pageViewController(_ pageViewController: UIPageViewController,
                        viewControllerAfter viewController: UIViewController) -> UIViewController? {
    guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
        return nil
    }

    let nextIndex = viewControllerIndex + 1
    let orderedViewControllersCount = orderedViewControllers.count

    guard orderedViewControllersCount != nextIndex else {
        return nil
    }

    guard orderedViewControllersCount > nextIndex else {
        return nil
    }

    return orderedViewControllers[nextIndex]
}

0 个答案:

没有答案