问题
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.
回答1:
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;
}
回答2:
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.
来源:https://stackoverflow.com/questions/14905902/uipageviewcontroller-programmatically-turning-pages-does-not-update-page-indicat