2

I'm using an existing project (https://github.com/ThornTechPublic/Onboarding-With-UIPageViewController-Final ) . I want to perform the slide with a boutton also. I want my button "Next" to do the same functionality as swiping so when the user taps it, it moves to the next screen. Button in blue . How to do that ? thanks in advance .

Aymen BRomdhane
  • 143
  • 1
  • 14

1 Answers1

1

Here is how I do it: I use an NSNotification on the page, that lets the OnboardingPager know when the button is pushed, and do the appropriate action.

Here's an example: in the StepZero page, I did the following

@IBAction func nextPressed(sender: UIButton) {
    NSNotificationCenter.defaultCenter().postNotificationName("testbutton", object: nil)
}

Then in the OnboardingPager class, I added the following

override func viewDidLoad() {
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(nextPage(_:)), name: "testbutton", object: nil)
}

func nextPage(notification:NSNotification) {
    self.setViewControllers([getStepOne()],
             direction: UIPageViewControllerNavigationDirection.Forward,
             animated: true,
             completion: nil)
}

This lets you go from the first page (StepZero) to the second (StepOne).

Daniel Sumara
  • 2,234
  • 20
  • 25
SoundShock
  • 485
  • 1
  • 3
  • 24