Page ViewController with 4 viewControllers - How to set view 2 as initial viewController?

让人想犯罪 __ 提交于 2019-12-03 00:42:28

问题


I have created a pageViewController with four view controller.

Right now the order is:

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]
}()

How can I set VC2 as the initial view controller of the page view controller when the app loads? So basically the user can swipe left "and" right to got to from VC2 left to VC1 or right from VC2 to VC3.

VC1 < VC2 - this is the start view controller > VC3 > VC4

This is my 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:


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


来源:https://stackoverflow.com/questions/48630208/page-viewcontroller-with-4-viewcontrollers-how-to-set-view-2-as-initial-viewco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!