即使在实现委托方法后也不显示页面控件

即使在实现委托方法后也不显示页面控件

本文介绍了即使在实现委托方法后也不显示页面控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

添加委托和数据源后页面视图控制器不显示.如何实现pageViewController数据源和委托

Page view controller not display after adding delegate and datasource. how to implement pageViewController Datasource and delegate

import UIKit

数据源

class PageViewController: UIPageViewController ,UIPageViewControllerDataSource,UIPageViewControllerDelegate
{
    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
        let vc = storyboard?.instantiateViewController(withIdentifier: "vc") as! ViewController

        return vc

    }
    func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
        let vc = storyboard?.instantiateViewController(withIdentifier: "vc") as! ViewController

        return vc
    }
    func presentationCount(for pageViewController: UIPageViewController) -> Int {
        return 3
    }
    override func index(ofAccessibilityElement element: Any) -> Int {
        return 0
    }

在 ViewDidLoad 中设置委托和数据源

setting a delegate and datasource in ViewDidLoad

    override func viewDidLoad() {
        super.viewDidLoad()
         dataSource=self
        delegate = self
        let vc = storyboard?.instantiateViewController(withIdentifier: "vc") as! ViewController
       self.setViewControllers([vc], direction: .forward, animated: true, completion: nil)

     }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

推荐答案

替换

 override func index(ofAccessibilityElement element: Any) -> Int {
        return 0
    }

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

完成工作.

我调用了错误的方法

这篇关于即使在实现委托方法后也不显示页面控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 04:01