I have a PageViewController
and three view controllers. I want to move to previous and next page with button click. I have three VCs and when I run, I'm in the second one, (main).
Ordered items: (in MainViewController
class), and pageViewController
is an instance of PageViewController
class.
override func viewDidLoad() {
super.viewDidLoad()
orderedItems = self.pageViewController.orderedViewControllers
}
orderdViewControllers
in PageViewController
Class
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)")
}
this is my code for button taps: (in MainViewController
class)
@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)
}
but it fails, nothing happens. How can I do it?