no page control displayed even after implementing delegate methods

前提是你 提交于 2019-12-14 03:32:39

问题


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

import UIKit

DataSource

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
    }

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.
    }


}

回答1:


Replacing

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

with

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

did the work.

I was calling wrong method



来源:https://stackoverflow.com/questions/42196932/no-page-control-displayed-even-after-implementing-delegate-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!