在Swift 3.0中编码,我有一个页面视图控制器设置有三个不同的视图。我想在viewDidLoad中加载中间视图控制器?

时间:2017-03-16 17:10:54

标签: ios swift uipageviewcontroller

$我想在启动时首先加载中间视图控制器,以便用户可以从头开始向右或向左滑动。

override func viewDidLoad() {
    super.viewDidLoad()
    dataSource = self
    self.delegate = self
    configurePageControl()

$这是我设置第一个视图控制器开始的地方,但我希望首先加载中间控制器。

    if let firstViewController = orderedViewControllers.first {

        setViewControllers([firstViewController], direction: .forward, animated: true, completion: nil)
    }

}

//==============================================================
// MARK: - Properties
//==============================================================
var pageControl = UIPageControl()

//==============================================================
// MARK: - The array of viewControllers
//==============================================================
private(set) lazy var orderedViewControllers: [UIViewController] = {
    return [self.newViewController(view: "Main"), self.newViewController(view: "UserSetting"), self.newViewController(view: "Detail")]
}()

private func newViewController(view: String) -> UIViewController {
    return UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "\(view)ViewController")
}

1 个答案:

答案 0 :(得分:1)

如果您希望第二页成为默认页面 - 您登陆的第一页,则只需更改:

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

if orderedViewControllers.count > 1 {
    setViewControllers([orderedViewControllers[1]], direction: .forward, animated: true, completion: nil)
}