Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPageViewController display hierarchy

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?

like image 680
Zian Chen Avatar asked Aug 06 '26 15:08

Zian Chen


1 Answers

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.

like image 155
Léo Natan Avatar answered Aug 08 '26 09:08

Léo Natan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!