ios - 为什么我收到错误 'Type ViewController does not conform to protocol UIPageViewControllerDataSource'?

标签 ios swift delegates datasource uipageviewcontroller

我希望设置一个 VC 来处理我的 UIPageViewControllerDataSource,但无论出于何种原因,我都会收到此错误。我需要包括另一个协议(protocol)吗?我的代码:

class ViewController: UIViewController, UIPageViewControllerDelegate, UIPageViewControllerDataSource

谢谢!

最佳答案

为自定义类添加协议(protocol)定义是不够的。您必须至少提供 UIPageViewControllerDataSource 协议(protocol)的两个必需函数:

func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? 

func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?

仔细查看您可以在 UIPageViewControllerDataSource Protocol Reference 中的类中实现的方法文档。

关于ios - 为什么我收到错误 'Type ViewController does not conform to protocol UIPageViewControllerDataSource'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33417831/

相关文章:

ios - 为什么 "Add Accessory" View Controller 在长时间延迟后才出现?

swift - 从 TableView 内的 Collection View 执行 segue 单击按钮

ios - Swift ViewController,objective C 协议(protocol),类型 'ViewController' 不符合协议(protocol) 'MyProtocolDelegate'

iphone - 我们可以一次使用排序描述符和@distinctUnionOfObjects吗?

ios - Unwind Segue - 在哪里拖动退出?

ios - 如何从 ios 中的类方法中删除 subview ?

IOS Swift 在使用 nib 文件进行可重用 View 时出现混淆错误

ios - Youtube 帮助播放器查看 iOS iPhone X 布局问题

ios - 我怎样才能只显示网站的内容?

c# - .NET 中的传统循环与 Action 委托(delegate)