0

I'm using UIPageViewController to display 3 viewcontrollers. If I move to the third and then go back to the first view controller, the first view controller is deallocated from memory. How can I fix this while still using UIPageViewController or is it just not the intended use of UIPageViewController?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Atharva Vaidya
  • 754
  • 1
  • 5
  • 12

1 Answers1

1

Keep a strong reference to the UIViewController's either with an array, or individually in your UIPageViewController. Note that when the device runs low on memory, the controllers will unload their views.

Swift:

class PageViewController: UIPageViewController {
    var viewControllers: [UIViewController]?
    // or
    var viewControllerA: UIViewController?
    var viewControllerB: UIViewController?
    var viewControllerC: UIViewController?
}

Objective-C:

@interface PageViewController: UIPageViewController

@property (nonatomic, strong) NSMutableArray* viewControllers;
// or
@property (nonatomic, strong) UIViewController* viewControllerA;
@property (nonatomic, strong) UIViewController* viewControllerB;
@property (nonatomic, strong) UIViewController* viewControllerC;

@end
dennykim
  • 329
  • 1
  • 3
  • Good point, I do that but it still hides them on each side :/ https://stackoverflow.com/q/76055638/294884 – Fattie Apr 19 '23 at 14:40