使用UIPageViewControllerDataSource时,在UIPageViewController中以编程方式翻页? [英] Turn page programmatically in UIPageViewController when using UIPageViewControllerDataSource?
问题描述
我有一个 UIPageViewController
和一个符合 UIPageViewControllerDataSource
的类,并管理UIPageViewController显示的UIViewControllers。当用户启动翻页时,一切运行良好。但是现在我想以编程方式做到这一点。
I have an UIPageViewController
and a class which conforms to UIPageViewControllerDataSource
and manages the UIViewControllers which UIPageViewController displays. It all runs well when turning the pages is initiated by the user. But now I want to do that programmatically.
我发现在SO上有一个非常类似的问题,它回答了静态数量的ViewControllers的问题:< a href =https://stackoverflow.com/questions/7208871/is-it-possible-to-turn-page-programmatically-in-uipageviewcontroller>是否可以在UIPageViewController中以编程方式翻页?
I've found that there is a very similar question here on SO which answers the question for a static amount of ViewControllers: Is it possible to Turn page programmatically in UIPageViewController?
但是我无法调整使用UIPageViewControllerDataSource的答案。我当时认为必须有这样的东西:
But I'm unable to adapt the answers to the use of UIPageViewControllerDataSource. I was thinking that there must be something like:
- (void)setCurrentViewController:(UIViewController *)viewController
我想我只是在这里忽略了一些东西。
I suppose I'm just overlooking something here.
推荐答案
答案中提到的方法( setViewControllers:direction:animated:completion:
)设置当前视图控制器而这正是你所需要的。
使用第一个参数定义视图控制器,您想要显示。如果您没有书脊,请使用一个,如果您预订左/右使用两个。
The Method mentioned in the answer ( setViewControllers:direction:animated:completion:
) sets the current view controller and is exactly what you need.
With the first param you define the view controller(s), you want to display. Use one if you don't have a spine, if you book is left/right use two.
这篇关于使用UIPageViewControllerDataSource时,在UIPageViewController中以编程方式翻页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!