2017-02-13 71 views
-1

頁面視圖控制器在添加委託和數據源後不顯示。如何實現pageViewController數據源和委託即使執行委託方法後也不顯示頁面控制

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

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

更換

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

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

所做的工作。

我打電話錯誤的方法

0
class PageViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // set datasource 
     self.dataSource = self 
     // set delegate 
     self.delegate = self 
     // set your current controller 
     setViewControllers([<#YourViewController#>], direction:UIPageViewControllerNavigationDirection.forward, animated: false, completion: nil) 
    } 
} 

數據源

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { 
     //return your before Controller here 
     return <#Your Controller Which place before#> 
    } 

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

     //return your after Controller here 
     return <#Your Controller Which place after#> 

    } 

的頁面控制器實現委託作爲跟隨

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController { 
    // The number of items reflected in the page indicator. 
    return 5; 
} 

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController { 
    // The selected item reflected in the page indicator. 
    return 0; 
} 
+0

我仍然無法看到頁面控制 – CazzyTheCoder

+0

你不能看到什麼?頁面控制器/ pageViewController –

+0

頁面控制器 – CazzyTheCoder