The problem here is that you are referencing two completely different objects.
In viewDidLoad you create ThongTinBNPage2 viewController and then add it to the viewControllers property of the pageViewController. However, the objects stored in VCArr are two totally different viewControllers.
Let’s think about it this way:
- When
viewDidLoadis called you create viewControllerobject #1 - Then you assign the viewController
object #1to the viewControllers object of the pageViewController making the value ofviewControllers = [object #1] - In
pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController?andpageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?you reference the VCArr object. On the first call to VCArr, it lazily creates two completely different view controller objects[object #2, object #3]
To fix this code you need to do the following:
if let firstVC = VCArr.first {
let subjective = firstVC // DO NOT create different VC here
subjective.lblhoten = lblhoten
subjective.lblngaysinh = lblngaysinh
subjective.lblsodt = lblsodt
setViewControllers([subjective], direction: .Forward, animated: true, completion: nil)
}
1
solved When I pass data from TableView to child PageViewController, it can go to next child