在Swift3上开发一个演练屏幕

时间:2016-10-26 17:34:32

标签: ios swift

我在Swift中很新,我正在尝试为我的应用程序开发一个演练屏幕。我正在阅读一本书教程,但是我收到了以下错误,我无法继续。

我认为问题在于Swift的不同更新。你能帮我解决一下吗?

self.pageViewController = (self.storyboard?.instantiateViewController(withIdentifier: "pageViewController") as! UIPageViewController!) as! UIPageViewControllerDataSource!

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

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

self.addChildViewController(pageViewController as! UIViewController)
self.view.addSubview(pageViewController.view)

self.pageViewController.didMoveToParentViewController(self)

enter image description here

1 个答案:

答案 0 :(得分:0)

pageViewController类型为UIPageViewControllerDataSource。这是一个协议,而不是UIViewController 您无需将UIPageViewController投射到UIPageViewControllerDataSource。您需要实施UIPageViewControllerDataSource并设置pageViewController数据源。

var pageViewController: UIPageViewController

self.pageViewController = self.storyboard?.instantiateViewController(withIdentifier: "pageViewController") as! UIPageViewController
self.pageViewController.datasource = self

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

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

self.addChildViewController(pageViewController as! UIViewController)
self.view.addSubview(pageViewController.view)

self.pageViewController.didMoveToParentViewController(self)