当我使用类似于 this answer 的方法以编程方式在 UIPageViewController 中翻页时,页面指示器不会更新。滑动到下一页/上一页会按预期更新页面指示器。以编程方式翻页时,我需要做什么来更新页面指示器?即,如何在以编程方式更改页面后设置当前“索引”,以便页面指示器知道哪个页面指示器显示为事件状态?
我在文档中注意到,说明如下:
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.
(见上文粗体)
UIPageViewController documenatation
这是否意味着如果您不使用手势翻页,那么就没有办法更新 UIPageIndicators?
预先感谢您的帮助。
最佳答案
您可以使用正确的页面索引实现以下数据源协议(protocol)方法:
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
NSInteger currentPageIndex=0;
//find out actual page index of the current view controller
return currentPageIndex;
}
关于objective-c - UIPageViewController 以编程方式翻页不更新页面指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14905902/