为什么我收到错误' Type ViewController不符合协议UIPageViewControllerDataSource'?

时间:2015-10-29 15:05:19

标签: ios swift delegates datasource uipageviewcontroller

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

class ViewController: UIViewController, UIPageViewControllerDelegate, UIPageViewControllerDataSource

谢谢!

2 个答案:

答案 0 :(得分:1)

为自定义类添加协议定义是不够的。您必须至少提供UIPageViewControllerDataSource协议所需的两个功能:

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

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

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

答案 1 :(得分:0)

您必须实施以下方法:

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

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