Davide Nastasi
Davide Nastasi

Reputation: 13

Cannot invoke" 'setViewController' with an argument list of type [AnyObject]

"Cannot invoke" 'setViewController' with an argument list of type '([AnyObject], direction: UIPageViewControllerNavigationDirection, animated: Bool, completion: nil)'"

I got this error in Xcode 7 beta 3 at this line of code:

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

This is the rest of the code:

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)

I don't get the error if I run the same code in Xcode 6 and I can't figure out why.

Upvotes: 1

Views: 1111

Answers (2)

swnevol
swnevol

Reputation: 1

In xcode7.0, you may change it to

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

Upvotes: 0

idmean
idmean

Reputation: 14875

The signature looks like:

func setViewControllers(_ viewControllers: [UIViewController]?,
              direction direction: UIPageViewControllerNavigationDirection,
               animated animated: Bool,
             completion completion: ((Bool) -> Void)?)

So why are you casting to [AnyObject]?

Try

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

Depending on the type of viewControllers you might also need to use as!

Upvotes: 0

Related Questions