我在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)
答案 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)