gpt4 book ai didi

iOS页面浏览 Controller

转载 作者:行者123 更新时间:2023-11-30 14:01:02 25 4
gpt4 key购买 nike

我尝试设置 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 点中,“使用未声明的类型”。

最佳答案

情况1:PageController.dataSource = self

情况2:pageViewController = PageController

情况3:没有声明PageItemController类

案例4:案例3

情况 5:由于情况 3,itemController 未实例化

情况 6:由于情况 3 而无法识别返回类型

情况7:返回contenteImges.count

关于iOS页面浏览 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32998101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com