These two methods viewControllerBeforeViewController and viewControllerAfterViewController of the UIPageViewControllerDataSource don\'
Firstly in your viewControllerForIndex method assign viewcontroller.view.tag = index so that every viewcontroller.view has an assigned value
Have a currentIndex property which is initially assigned to that index of the viewcontroller which you have instantiated inside pageviewcontroller
Now in didFinishAnimating do the following
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
if !completed {
return // return if animation is not completed
}
let pCont = bottomDataContainer?.viewControllers?[0] as? CustomVC //take
out current VC
if currentIndex < pCont?.view.tag ?? 0 {
topNavView.goToNextDate()
}else{
topNavView.goToPrevDate()
}
selectedIndex = pCont?.view.tag ?? 0
}