“无法调用”'setViewController',其参数列表类型为'([AnyObject],direction:UIPageViewControllerNavigationDirection,animated:Bool,completion:nil)'“
我在这行代码中遇到了Xcode 7 beta 3中的这个错误:
self.pageViewController.setViewControllers(viewControllers as [AnyObject], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
这是代码的其余部分:
pageImages = NSArray(objects:"screenshot01","screenshot02","screenshot03")
self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("MyPageViewController") as! UIPageViewController
self.pageViewController.dataSource = self
var initialContenViewController = self.pageTutorialAtIndex(0) as TutorialPageContentHolderViewController
var viewControllers = NSArray(object: initialContenViewController)
self.pageViewController.setViewControllers(viewControllers as [AnyObject], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
self.pageViewController.view.frame = CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height-100)
self.addChildViewController(self.pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMoveToParentViewController(self)
如果我在Xcode 6中运行相同的代码并且无法弄清楚原因,我不会收到错误。
答案 0 :(得分:0)
签名如下:
func setViewControllers(_ viewControllers: [UIViewController]?,
direction direction: UIPageViewControllerNavigationDirection,
animated animated: Bool,
completion completion: ((Bool) -> Void)?)
那你为什么要投身[AnyObject]
?
尝试
self.pageViewController.setViewControllers(viewControllers as [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
根据viewControllers
的类型,您可能还需要使用as!
答案 1 :(得分:0)
在xcode7.0中,您可以将其更改为
self.pageViewController.setViewControllers(viewControllers as? [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)