UIPageViewController以编程方式翻页不会更新页面指示器 [英] UIPageViewController programmatically turning pages does not update Page Indicator

查看:287
本文介绍了UIPageViewController以编程方式翻页不会更新页面指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用类似于此答案的方法以编程方式在UIPageViewController中翻页时,页面指示器不会更新。滑动到下一页/上一页按预期更新页面指示符。在以编程方式翻页时,我需要做什么来更新页面指示器?即如何在以编程方式更改页面后设置当前索引,以便页面指示器知道哪个页面指示器显示为活动状态?

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:


如果实现了支持页面指示符中的两个方法,并且页面视图控制器的转换样式为UIPageViewControllerTransitionStyleScroll,页面指​​示器可见。在调用setViewControllers:direction:animated:completion:方法之后调用这两个方法。 在手势驱动导航之后,不会调用这些方法。索引会自动更新,预计视图控制器的数量将保持不变。

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

这是否意味着如果您不使用手势来翻页,那么就无法更新UIPageIndicators?

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

提前感谢您的帮助。

推荐答案

您可以使用正确的页面索引实现以下数据源协议方法:

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;
}

这篇关于UIPageViewController以编程方式翻页不会更新页面指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆