我正在使用 Xcode 8 默认的基于页面的应用程序,但我无法尝试跳转到特定页面(而不是左右滑动来转动)。我在 StackOverflow 上发现了类似的问题,但大多数答案都建议使用这种方法:
setViewControllers:direction:animated:completion
我不需要改变要显示的页数,那么我可以避免使用setViewControllers
吗?
看完Xcode的page-based application template,我觉得这个功能可能行得通:
func viewControllerAtIndex(_ index: Int, storyboard: UIStoryboard) -> DataViewController?
但是,我不知道从哪里获取参数 storyboard: UIStoryboard
,因为 ModelController(充当 UIPageViewControllerDataSource 的 Controller )不是 Storyboard的一部分。
最佳答案
传递给此方法的 View Controller 是那些在动画完成后可见的 View Controller 。使用数据源提供用户导航的附加 View Controller 。
定义页面 View Controller 界面时,您可以一次提供一个内容 View Controller (或一次两个,具体取决于书脊位置和双面状态)或根据需要使用数据源。当一次提供一个内容 View Controller 时,你使用
setViewControllers(_:direction:animated:completion:)
设置当前内容 View Controller 的方法。要支持基于手势的导航,您必须使用数据源对象提供 View Controller 。
页面 View Controller 的数据源负责按需提供内容 View Controller 并且必须符合
UIPageViewControllerDataSource
协议(protocol)。
委托(delegate)对象——一个符合
UIPageViewControllerDelegate
协议(protocol)——提供一些与外观相关的信息并接收有关手势启动转换的通知。
setViewControllers([<#Your ViewControllers#>], direction: .forward, animated: true, completion: nil)
更多信息
关于ios - 如何使用 UIPageViewController 跳转到特定页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45095539/