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 .
Asked
Active
Viewed 179 times
2
-
I'm voting to mark this question as duplicate: http://stackoverflow.com/questions/7208871/is-it-possible-to-turn-page-programmatically-in-uipageviewcontroller – Gerd Castan Jul 30 '16 at 17:38
-
Not the same issue mate ;) – Aymen BRomdhane Aug 01 '16 at 12:56
1 Answers
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