📅  最后修改于: 2022-03-11 15:00:57.899000             🧑  作者: Mango
//Very simple solution is here
//To change page (UIViewController) from a UIViewController, first get the instance of Parent ViewController (which will be UIPageViewController) and then set its current ViewController
//In my case I have a UIPageViewController named "UserDetailsPVC" and it contains 4 pages (UIViewControllers) which are as follows
PageOneVC:UIViewController
PageTwoVC:UIViewController
PageThreeVC:UIViewController
PageFourVC:UIViewController
//In the UIPageViewController lets define an array of pages
var pages:[UIViewController] = [
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PageOneVC"),
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PageTwoVC"),
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PageThreeVC"),
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PageFourVC")
]
//Now to change page of UIPageViewController from any of the UIViewController
// get parent view controller
let parentVC = self.parent as! UserDetailsPVC
// change page of PageViewController
parentVC.setViewControllers([parentVC.pages[1]], direction: .forward, animated: true, completion: nil)