Casey Perkins
Casey Perkins

Reputation: 1932

UIPageViewController goes to wrong controller when using UIPageViewControllerTransitionStyleScroll

This other case seems to describe a similar behavior, but the accepted solution did not change anything in my application: UIPageViewController navigates to wrong page with Scroll transition style

One of the functions of my app is to offer random flashcards from a large list of vocabulary words. Going forward is OK, but after reaching the end, something strange happens. I go backwards, and the correct controller is displayed, but the same controller is presented again when going backwards the next time. Then everything proceeds as normal. But always the double presentation of one of the controllers after reaching the end and then going backwards.

If I change the transition style to UIPageViewControllerTransitionStylePageCurl, the wrong behavior disappears. But page curl doesn't make sense in my application.

I'll post my code if you guys think it would be helpful, but based on the other post, and on the fact that it works OK using page curl style, this seems to be a bug in iOS with the scroll style that must be somehow compensated for.

Thanks for any help.

Upvotes: 1

Views: 1148

Answers (2)

Lim Thye Chean
Lim Thye Chean

Reputation: 9434

If you use setViewControllers to go to a new controller, you need to set the animated to NO for UIPageViewControllerTransitionStyleScroll.

Upvotes: 0

Casey Perkins
Casey Perkins

Reputation: 1932

The viewWillAppear method of the controllers added to the page view controller is the key to figuring out what the correct page is in a timely fashion. I had the viewWillAppear to report the key number that was originally passed to it (that allowed for data lookup) back to the controller that contains the page view controller, which was also the datasource. Then it searches the datasource array for that object and when it finds it, the correct index is established.

Upvotes: 1

Related Questions