Xcode 8.2:UIPageViewControllerDatasource方法失效。

4

我正在开发一个应用程序,它使用 UIPageViewController 来呈现两个主要的视图控制器。我正在对 UIPageViewController 进行子类化,并遵循 UIPageViewControllerDatasource 协议。该协议中的方法允许我设置我想要显示的视图控制器。但以下方法给了我麻烦。

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {}

并且。
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {}

问题在于编译器一直试图更改方法中的参数。它会建议我犯了一个错误,要么更改viewControllerAfter,要么更改viewControllerBefore。我一直陷入这个循环中,并出现了这个错误:“method 'pageViewController(_:viewControllerBefore:)' has different argument names from protocol 'UIPageViewControllerDatasource'”。 BEFORE enter image description here enter image description here 然后我按照建议进行更改,但问题仍然存在。 AFTER enter image description here enter image description here 我需要一些指导来解决这个问题。

你在这些方法上使用了 override 吗? - Caleb Kleveter
1
我也曾在Xcode 8.1中遇到过这个问题,当我实现了两种方法后,错误就消失了。 - Samantha
@Samantha,你是对的。两种方法都需要实现。谢谢。 - Brandon A
1个回答

4
据我的理解,您需要同时实现这两种方法。这样可以消除您的错误。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接