ios - 如何使用 UIPageViewController 跳转到特定页面?

标签 ios swift uikit

我正在使用 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)

更多信息

Apple Docs

Stackoverflow

关于ios - 如何使用 UIPageViewController 跳转到特定页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45095539/

相关文章:

IOS Flutter 运行 - 未连接设备

swift - 为什么 `Publishers.Map`会急切的消费上游值呢?

swift - 如何比较结构数组以查看哪些元素不同?

cocoa-touch - iPad应用程序中的字体问题

iphone - 继续在 UITableView 的 "bounce area"中交替行颜色

swift - 如何处理 podfile 库的 "header file not found"? ('XYZ.h' 文件未找到)- 在 Xcode 中

ios - ionic 卡在 iPhone 中滚动缓慢

iOS 7.1 黑色导航栏,颜色鲜艳

ios - 亚马逊 Cognito 与 SwiftUI

ios - 无法在 SwiftUI 中更改 View 的背景颜色