用按钮更改页面。 UIPageViewCotroller

时间:2016-08-05 11:54:19

标签: ios uipageviewcontroller swift3

我有一个PageViewController和三个视图控制器。我想按下按钮移动到上一页和下一页。我有三个VC,当我跑步时,我在第二个,(主要)。

订购商品:(在MainViewController类中),pageViewControllerPageViewController类的实例。

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

但它失败了,没有任何反应。我该怎么办?

0 个答案:

没有答案