user7778349
user7778349

Reputation:

PageviewController selected index to particular viewcontroller

I have pageViewcontroller which is automatically slideing from one page to other page.

When I click on the particular page, I want to go to Another ViewController, I have seen many apps which displaying offer in a slide, when we click the slide index, it will go to the particular page.

Upvotes: 0

Views: 819

Answers (1)

Y.Bonafons
Y.Bonafons

Reputation: 2359

Simply add this on your UIPageControl:

pageControl.addTarget(self, action: #selector(pageChanged(_:)), for: .valueChanged)

Then catch the event:

@objc func pageChanged(_ sender: UIPageControl) {
    // Go to the appropriate controller
    let controllerToDisplay = UIViewController() // pick the appropriate controller here
    self.setViewControllers([controllerToDisplay], direction: .forward, animated: true, completion: nil)
}

Upvotes: 2

Related Questions