使用下面的代碼,我有一系列嵌入在頁面視圖控制器中的視圖控制器,我正在瀏覽。我只是無法找到一種方式通過按下按鈕來繼續到另一個視圖控制器。我打算爲每個視圖控制器中的每個欄按鈕圖標編寫一個單獨的函數。在頁面視圖控制器中更改VC的索引(Swift)
class PageViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
private var pages: [UIViewController]!
override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
self.delegate = self
self.pages = [
self.storyboard!.instantiateViewControllerWithIdentifier("FirstNav") as! UINavigationController,
self.storyboard!.instantiateViewControllerWithIdentifier("SecondNav") as! UINavigationController,
self.storyboard!.instantiateViewControllerWithIdentifier("ThirdNav") as! UINavigationController,
self.storyboard!.instantiateViewControllerWithIdentifier("FourthNav") as! UINavigationController
]
let startingViewController = self.pages.first! as UIViewController
self.setViewControllers([startingViewController], direction: .Forward, animated: false, completion: nil)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let index = (self.pages as NSArray).indexOfObject(viewController)
// if currently displaying last view controller, return nil to indicate that there is no next view controller
return (index == self.pages.count - 1 ? nil : self.pages[index + 1])
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
let index = (self.pages as NSArray).indexOfObject(viewController)
// if currently displaying first view controller, return nil to indicate that there is no previous view controller
return (index == 0 ? nil : self.pages[index - 1])
}
}
您嘗試Segue公司從視圖控制器其視圖控制器,並把欄按鈕,你在哪裏嘗試? – Frankie
上面的代碼是頁面視圖控制器的代碼。由於按鈕代碼有不同的按鈕,因此條形碼代碼會進入所有子視圖控制器。我需要從FirstNav繼續ThirdNav等等。 – chicobermuda