Swift - PageViewController jump to page

1.2k views Asked by At

I have a very simple app using a pageviewcontroller. This works fine using the gesture but how can I jump to the next or previous index / page using a button?

Thank you all

Cheers

Chris

1

There are 1 answers

0
Özgür Ersil On

you can init your new View Controller class and change the current view to new view like that:

    ///In viewDidLoad 
    let myFirstButton = UIButton()
    myFirstButton.addTarget(self, action: "pressed:", forControlEvents: .TouchUpInside)
    self.view.addSubview(myFirstButton)
    //////

    func pressed(sender:UIButton!) {
        let vc = YourNewViewController() //change this to your class name
        self.presentViewController(vc, animated: true, completion: nil)
    }