I have a weird problem with a UIPageViewController
. I use it to display several pages of data.
In case there is more than two pages, I let the user cycle through them, meaning he will see the first page again when scrolling further on the last page.
When I dismiss the pageController
it gets properly deallocated and I don't capture the single controllers that are displayed inside of it separately. Still when I open the pageController
again with a different dataset, I sometimes see one more page from the previous dataset.
To make my problem a little clearer, this is an example of what happens:
- I open the page controller with two images, a cat and a dog
- I close the page controller, it gets properly deallocated
- I open it again, this time with three images, a horse, a bird and a cow
- In addition to those three pages I see a fourth one displaying the cat from before
This is how my UIPageViewController
is setup:
let pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
let controllers = dataModels.enumerated().map { index, dataModel in
let vc = DetailsController(model: dataModel)
vc.view.tag = index
return vc
}
pageViewController.delegate = self
pageViewController.dataSource = controllers.count > 1 ? self : nil
pageViewController.setViewControllers([controllers[0]], direction: .forward, animated: true, completion: nil)
So my question is: how can it be that the pageController
gets deallocated and still somehow captures old data when it is opened again later?