具有4个viewControllers的页面ViewController - 如何将视图2设置为初始viewController?

时间:2018-02-05 19:38:25

标签: ios swift uipageviewcontroller

我创建了一个带有四个视图控制器的pageViewController。

现在订单是:

VC1,VC2,VC3,VC4:

var pageControl = UIPageControl()
var pendingPage: Int?

lazy var viewControllerList: [UIViewController] = {
    let sb = UIStoryboard(name: "Main", bundle: nil)

    let vc1 = sb.instantiateViewController(withIdentifier: "VC1")
    let vc2 = sb.instantiateViewController(withIdentifier: "VC2")
    let vc3 = sb.instantiateViewController(withIdentifier: "VC3")
    let vc4 = sb.instantiateViewController(withIdentifier: "VC4")

    return [vc1, vc2, vc3, vc4]
}()

如何在应用加载时将VC2设置为页面视图控制器的初始视图控制器?所以基本上用户可以向左滑动“和”向右滑动从VC2左转到VC1或从VC2转到VC3。

VC1< VC2 - 这是起始视图控制器> VC3> VC4

这是我的viewDidLoad():

override func viewDidLoad() {
    super.viewDidLoad()

    self.delegate = self
    self.dataSource = self

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

1 个答案:

答案 0 :(得分:0)

    self.setViewControllers([viewControllerList[1]], direction: .forward, animated: true, completion: nil)