gpt4 book ai didi

ios - 无法使用 [AnyObject] 类型的参数列表调用“'setViewController'”

转载 作者:行者123 更新时间:2023-11-28 09:01:39 26 4
gpt4 key购买 nike

“无法使用类型为‘([AnyObject],方向:UIPageViewControllerNavigationDirection,动画:Bool,完成:nil)’的参数列表调用”‘setViewController’”

我在 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 中运行相同的代码,我不会收到错误,而且我无法弄清楚原因。

最佳答案

签名看起来像:

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!

关于ios - 无法使用 [AnyObject] 类型的参数列表调用“'setViewController'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31885484/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com