简体   繁体   中英

no page control displayed even after implementing delegate methods

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


}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM