Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIPageViewController点不显示_Ios_Swift_Xcode_Cocoa Touch_Uipageviewcontroller - Fatal编程技术网

Ios UIPageViewController点不显示

Ios UIPageViewController点不显示,ios,swift,xcode,cocoa-touch,uipageviewcontroller,Ios,Swift,Xcode,Cocoa Touch,Uipageviewcontroller,一切正常,但圆点不显示。我的代码是 import UIKit class MyPageViewController: UIPageViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. dataSource = self if let firstViewController

一切正常,但圆点不显示。我的代码是

import UIKit

class MyPageViewController: UIPageViewController  {

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    dataSource = self

    if let firstViewController = orderedViewControllers.first {
        setViewControllers([firstViewController],
                           direction: .forward,
                           animated: true,
                           completion: nil)
    }

}

private(set) lazy var orderedViewControllers: [UIViewController] = {

    return [self.newColoredViewController(color: ""),
            self.newColoredViewController(color: "Second"),
            self.newColoredViewController(color: "Third")]
}()

private func newColoredViewController(color: String) -> UIViewController {

    return UIStoryboard(name: "Main", bundle: nil) .
        instantiateViewController(withIdentifier: "\(color)ViewController")
}

}


// MARK: UIPageViewControllerDataSource

extension MyPageViewController: UIPageViewControllerDataSource {

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {

        guard let viewControllerIndex = orderedViewControllers.firstIndex(of: viewController) else {
            return nil
        }

        let previousIndex = viewControllerIndex - 1

        guard previousIndex >= 0 else {
            return nil
        }

        guard orderedViewControllers.count > previousIndex else {
            return nil
        }

        return orderedViewControllers[previousIndex]
    }

    func pageViewController(_ pageViewController: UIPageViewController,
                            viewControllerAfter viewController: UIViewController) -> UIViewController? {
        guard let viewControllerIndex = orderedViewControllers.firstIndex(of: viewController) else {
            return nil
        }

        let nextIndex = viewControllerIndex + 1
        let orderedViewControllersCount = orderedViewControllers.count

        guard orderedViewControllersCount != nextIndex else {
            return nil
        }

        guard orderedViewControllersCount > nextIndex else {
            return nil
        }

        return orderedViewControllers[nextIndex]
    }

    func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
        setupPageControl()
        return orderedViewControllers.count
    }

    func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
        return 0
    }

    private func setupPageControl() {
        let appearance = UIPageControl.appearance()
        appearance.pageIndicatorTintColor = UIColor.darkGray
        appearance.currentPageIndicatorTintColor = UIColor.red
        appearance.backgroundColor = UIColor.black
    }

}


您使用的这些函数的版本不正确

为了显示UIPageControl,您需要实现两个可选的数据源方法。只需返回presentationCount的完整页数和presentationIndex

func presentationCount(for pageViewController: UIPageViewController) -> Int {
    setupPageControl()
    return orderedViewControllers.count
    }

func presentationIndex(for pageViewController: UIPageViewController) -> Int {
    return 0
    }

您使用的这些函数的版本不正确

为了显示UIPageControl,您需要实现两个可选的数据源方法。只需返回presentationCount的完整页数和presentationIndex

func presentationCount(for pageViewController: UIPageViewController) -> Int {
    setupPageControl()
    return orderedViewControllers.count
    }

func presentationIndex(for pageViewController: UIPageViewController) -> Int {
    return 0
    }

您应该添加页面视图控制器数据源和页数:
pageControl.numberOfPages=3

您应该添加页面视图控制器数据源和页数:

pageControl.numberOfPages=3

您是否在故事板中使用
UIPageViewControllerTransitionStyleScroll
,请参阅我更新的问题此方法调用了
presentationCountForPageViewController
?没有调用…presentationCountForPageViewController在数据源中,因此它很好。如果您有教程中的复制粘贴代码,那么请确保它符合最新的swift语法。您是否在故事板中使用了
UIPageViewControllerTransitionStyleScroll
,我修复了它,请参阅我更新的问题此方法已调用?否未调用…presentationCountForPageViewController位于数据源中,因此可以。若你们有教程中的复制粘贴代码,那个么确保它符合最新的swift syntaxYes,它可以工作,但背景是黑色的。如何将UIPageControl backgroundColor设置为白色:UIPageControl.appearance().backgroundColor=UIColor.white@Hitesh Borse,谢谢,但它不能满足我的要求。请建议如何将PageViewController添加到exist ViewController并加载一个或三个ViewController。你能为我推荐一些代码或教程吗?谢谢,这段代码对我来说没什么变化,是的,它可以工作,但是背景颜色变黑了。如何将UIPageControl backgroundColor设置为白色:UIPageControl.appearance().backgroundColor=UIColor.white@Hitesh Borse,谢谢,但它不能满足我的要求。请建议如何将PageViewController添加到exist ViewController并加载一个或三个ViewController。你能为我推荐一些代码或教程吗?谢谢,这些代码对我来说很有用,只做了一些改动,