A
A
Aleksandr Govorukhin2017-05-18 20:13:54
iOS
Aleksandr Govorukhin, 2017-05-18 20:13:54

How to navigate between pages using PageViewController Swift 3 button?

Hello!
Everything works stably, but I decided to add a button transition, the error is simple, but I don’t see a solution point blank. The bottom line is that with the help of a button, he can only go to page 2, there are no problems with a swipe. Tell me what to fix. Thank you!

@IBAction func nextPage(sender: AnyObject) {
        let pageViewController = self.parent as! PageViewController
        pageViewController.nextPage(index: 1)
    }


func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
        var index = (viewController as! ContentPageViewController).index
        index -= 1
        return self.showViewControllerAtIndex(index: index)
    }
    
    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
        var index = (viewController as! ContentPageViewController).index
        index += 1
        return self.showViewControllerAtIndex(index: index)
    }
    
    func nextPage(index: Int) {
        if let nextVC = self.showViewControllerAtIndex(index: +1) {
            setViewControllers([nextVC], direction: .forward, animated: true, completion: nil)
        }
        
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
ManWithBear, 2017-05-18
@SnapSh0t

So you hardcoded that you want to go to the second page:
pageViewController.nextPage(index: 1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question