gpt4 book ai didi

ios - 已经显式地将 NSArray 转换为 [AnyObject] 但仍然收到错误

转载 作者:行者123 更新时间:2023-11-30 13:53:44 26 4
gpt4 key购买 nike

嗨,我刚刚将我的 xcode 更新到最新版本(我认为是 7.1.1),然后我收到错误消息,指出 NSArray 不能隐式转换为 AnyObject,从这一行开始: self .pageViewController.setViewControllers(viewControllers as [AnyObject],方向:.Forward,动画:true,完成:nil)

viewControllers 是一个 NSArray 类型。它建议我使用“AS”来显式转换。不过,我想我已经这么做了。为什么我仍然收到错误?是格式问题吗?谢谢!

class ViewController: UIViewController, UIPageViewControllerDataSource {

var pageViewController: UIPageViewController!
var pageTitles: NSArray!
var pageImages: NSArray!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.pageTitles = NSArray(objects: "hi","hey")
self.pageImages = NSArray(objects: "1","2")
self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PageViewController")as! UIPageViewController
self.pageViewController.dataSource = self

var startVC = self.viewControllerAtIndex(0) as ContentViewController
var viewControllers = NSArray(object:startVC)

self.pageViewController.setViewControllers(viewControllers as [AnyObject], direction:.Forward, animated: true, completion: nil)


self.pageViewController.view.frame = CGRectMake(0, 30, self.view.frame.width, self.view.frame.height-60)

self.addChildViewController(self.pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMoveToParentViewController(self)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.

}

最佳答案

setViewControllers:direction:animated:completion: 的第一个参数声明为 [UIViewController]? 而不是 [AnyObject]?

也许这就足够了:

let startVC = self.viewControllerAtIndex(0) as ContentViewController
self.pageViewController.setViewControllers([startVC], direction:.Forward, animated: true, completion: nil)

关于ios - 已经显式地将 NSArray 转换为 [AnyObject] 但仍然收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33931266/

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