$
我想在启动时首先加载中间视图控制器,以便用户可以从头开始向右或向左滑动。
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")
}
答案 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)
}