我有一个PageViewController
和三个视图控制器。我想按下按钮移动到上一页和下一页。我有三个VC,当我跑步时,我在第二个,(主要)。
订购商品:(在MainViewController
类中),pageViewController
是PageViewController
类的实例。
override func viewDidLoad() {
super.viewDidLoad()
orderedItems = self.pageViewController.orderedViewControllers
}
orderdViewControllers
班级中的 PageViewController
private(set) lazy var orderedViewControllers: [UIViewController]? = {
return [
self.newViewController(id: "first"),
self.newViewController(id: "main"),
self.newViewController(id: "second")
]
}()
private func newViewController(id: String) -> UIViewController {
return UIStoryboard(name: "Main", bundle: nil) .
instantiateViewController(withIdentifier: "\(id)")
}
这是我的按钮点击代码:(在MainViewController
类中)
@IBAction func leftBtnPressed(_ sender: AnyObject) {
self.pageViewController.setViewControllers([(orderedItems?.first)!], direction: .reverse, animated: true, completion: nil)
}
@IBAction func rightBtnPressed(_ sender: AnyObject) {
self.pageViewController.setViewControllers([(orderedItems?.last)!], direction: .forward, animated: true, completion: nil)
}
但它失败了,没有任何反应。我该怎么办?