2015-09-26 27 views
0

我使用嵌入在Container中的pageViewController作爲主屏幕,作爲ViewController。 ViewController有幾個按鈕來打開其他ViewController。如何移動到pageViewController中的特定頁面?

我正在尋找一種方法來更新pageViewController當前頁面的基礎上保存數據在不同的ViewController時設置的變量的值。我設法值進入主ViewController和幾乎能夠使它在viewDidLoad與此代碼工作的家庭ViewController

if currentStatPage > 0 { 
    startVC = self.viewControllerAtIndex(currentStatPage) as ViewControllerDashboardCharts 
    viewControllers = NSArray(object: startVC) 
    self.pageViewController.setViewControllers(viewControllers as! [UIViewController], direction: .Forward, animated: true, completion: nil) 
    var pageController = UIPageControl.appearance() 
    pageController.currentPage = currentStatPage 

} 

的問題是,是我選擇按鈕,將顯示頁面#3(發送值2),pageViewController中的頁面出現亂序(第1頁到達第2頁的位置)。

有沒有辦法預先載入6個ViewControllers(動態創建)並以編程方式移動到特定的?

任何幫助將不勝感激,謝謝。

回答

0

問題是presentationIndexForPageViewController。我有一個返回0的代碼,當將返回值更改爲當前頁面索引時,問題消失了。

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

} 
相關問題