UIPageViewController programmatically turning pages does not update Page Indicator

只谈情不闲聊 提交于 2020-01-14 16:36:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!