2017-06-20 56 views
-2

UIPageViewControllerDelegate斯威夫特,如何獲取當前顯示控制器UIPageViewController

func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { 
    let viewer = pageViewController.childViewControllers[0] as! KKPhotoViewerController //So I got controller is a constant 
    print(pageViewController.childViewControllers) 
    print(previousViewControllers) 
    photos.selectedIndex = viewer.photoIndex 
    currentViewer = viewer 
} 
+0

歡迎計算器!請參考這個stackoverflow.com/help/how-to-ask –

+0

像這樣我會去控制器目前沒有顯示 –

回答

0

試試這個:

if self.pageViewController?.viewControllers?.count > 0 { 
    let currentController = self.pageViewController?.viewControllers![0] 
} 
+0

非常感謝!我應該採取'pageViewController.viewControllers?[0]'而不是'pageViewController.childViewControllers [0]' –