无法将类型' [AnyObject]&#39的值转换为预期的参数类型' [UIViewController]?'

时间:2016-02-11 15:12:00

标签: ios swift swift2

private func createPageViewController() {
    let pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PageViewController") as! UIPageViewController
    pageViewController.dataSource = self
    pageViewController.delegate = self

    if contentImages.count > 0 {
        let firstVC = self.getItemController(0)!
        let startingVCs: NSArray = [firstVC]
        pageViewController.setViewControllers(startingVCs as [AnyObject] as [AnyObject], direction: .Forward, animated: false, completion: nil)
    }

1 个答案:

答案 0 :(得分:1)

更改此

pageViewController.setViewControllers(startingVCs as [AnyObject] as [AnyObject], direction: .Forward, animated: false, completion: nil)

进入

viewControllers参数现在是[UIViewController]。因此,您传入的viewControllers数组必须为[UIViewController]

pageViewController.setViewControllers(startingVCs as [UIViewController], direction: .Forward, animated: false, completion: nil)