3

I have a UIPageViewController that contains multiple view controllers (self is a subclass of UIPageViewController, and I just put in one view controller here to demonstrate my question):

ViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[self setViewControllers:@[viewController] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];

If I put a log in both self and ViewController class, seems like the viewDidAppear in ViewController class gets called BEFORE the viewDidAppear in UIPageViewController.

The problem I have is I need to check visibleCells method in collectionView that's embedded in ViewController class. In this scenario, the visible cells method is returning empty array of cells (since it gets called before UIPageViewController is ready to show). However, everything works fine when I am not using the UIPageViewController as a container.

I tried addChildViewController to see if I have any luck but it's not working (obviously). Is there a way in UIPageViewController that can manage the flow of view cycle?

Neeku
  • 3,646
  • 8
  • 33
  • 43
Zian Chen
  • 510
  • 1
  • 5
  • 11

1 Answers1

2

Page view controller has many bugs related to displaying views. Perhaps a more correct place to add your logic is viewDidLayoutSubviews since this will be called whenever a layout pass has occurred and the frame of the view might have changed.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195