我尝试设置UIPageViewController
组件,但我不能。我该如何解决?
这是我的一段代码:
import UIKit
class ViewController: UIViewController, UIPageViewControllerDataSource {
private var pageViewController: UIPageViewController?
private let contenteImges = ["7272LOGO",
"spBc",
"tuto1"]
override func viewDidLoad() {
super.viewDidLoad()
createPageViewController()
setupPageControl()
// Do any additional setup after loading the view, typically from a nib.
}
private func createPageViewController()
{
let PageController = self.storyboard!.instantiateViewControllerWithIdentifier("PageController") as! UIPageViewController
pageController.dataSource = self
if contenteImges.count > 0
{
let firstController = getItemController(0)!
let startingViewControllers: NSArray = [firstController]
PageController.setViewControllers(startingViewControllers as! [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
}
pageViewController = pageController
addChildViewController(pageViewController!)
self.view.addSubview(pageViewController!.view)
pageViewController!.didMoveToParentViewController(self)
}
private func setupPageControl() {
let appearance = UIPageControl.appearance()
appearance.pageIndicatorTintColor = UIColor.grayColor()
appearance.currentPageIndicatorTintColor = UIColor.whiteColor()
appearance.backgroundColor = UIColor.darkGrayColor()
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
let itemController = viewController as PageItemController
if itemController.itemIndex > 0 {
return getItemController(itemController.itemIndex-1)
}
return nil
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let itemController = viewController as PageItemController
if itemController.itemIndex+1 < contentImages.count {
return getItemController(itemController.itemIndex+1)
}
return nil
}
private func getItemController(itemIndex: Int) -> PageItemController?
{
}
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
return contentImages.count
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
它会在七行上抛出错误:
1。pageController.dataSource = self
2。pageViewController = pageController
3。let itemController = viewController as PageItemController
4。let itemController = viewController as PageItemController
5。if itemController.itemIndex+1 < contentImages.count {
6。private func getItemController(itemIndex: Int) -> PageItemController?
7。return contentImages.count
在第1,2,5和7点,它显示了“使用未解析的标识符”。在第3,4和6点,“使用未申报的类型”。
答案 0 :(得分:0)
案例1:PageController.dataSource = self
案例2:pageViewController = PageController
案例3:没有PageItemController类的声明
案例4:案例3
案例5:由于案例3
,itemController未实例化案例6:由于案例3而无法识别的返回类型
案例7:return contenteImges.count