UIPageViewController programmatically turning pages does not update Page Indicator
Asked Answered
O

2

4

When I programmatically turn the page in a UIPageViewController using a method similar to this answer, the Page Indicators are not updated. Swiping to the next/previous page updates the page indicators as expected. What do I need to do to update the Page Indicators when programmatically turning the page? i.e. How do I set the current "index" after programmatically changing the page so the Page Indicators know which page indicator to show as active?

I noticed in the documentation, the following is stated:

If both of the methods in “Supporting a Page Indicator” are implemented and the page view controller’s transition style is UIPageViewControllerTransitionStyleScroll, a page indicator is visible. Both of these methods are called after the setViewControllers:direction:animated:completion: method is called. After gesture-driven navigation, these methods are not called. The index is updated automatically and the number of view controllers is expected to remain constant.

(see bold text above)

UIPageViewController documenatation

Does this imply that if you don't use a gesture to turn the page, then there is no way to update the UIPageIndicators?

Thanks in advance for your help.

Ontologism answered 16/2, 2013 at 1:19 Comment(0)
A
4

You can implement the following data source protocol method with the correct page index:

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
 NSInteger currentPageIndex=0;
 //find out actual page index of the current view controller
return currentPageIndex;
}
Appellative answered 6/2, 2015 at 0:6 Comment(0)
P
0

It means that you are setting the number of pages and the first page one time, and cannot add (or remove) pages to the Page Control without calling setViewControllers:direction:animated:completion: again.

It is basically a write-only property defined in the DataSource protocol.

Prostyle answered 27/2, 2013 at 23:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.