Jamie Baker
Jamie Baker

Reputation: 157

Why am i getting the error 'Type ViewController does not conform to protocol UIPageViewControllerDataSource'?

I am looking to set up a VC that handles my UIPageViewControllerDataSource but for whatever reason I am getting this error. Is there another protocol I need to include. My code:

class ViewController: UIViewController, UIPageViewControllerDelegate, UIPageViewControllerDataSource

Thanks!

Upvotes: 0

Views: 726

Answers (2)

Cesare
Cesare

Reputation: 9409

Adding the protocol definition for your custom class is not enough. You have to provide at least the two required functions of the UIPageViewControllerDataSource protocol:

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

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

Take a close look at the methods you can implement within your class in the UIPageViewControllerDataSource Protocol Reference documentation.

Upvotes: 1

Manuel
Manuel

Reputation: 1695

You have to implement the following methods:

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

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

Upvotes: 0

Related Questions