How do I ensure that the viewWillAppear: and viewDidAppear: methods (and other transition methods) are called in the UIPageViewController's ViewControllers ?
In my case, the browsing methods are adequately called on all but the firstViewController itself, which is opened by the UIPageViewController . In doing so, the firstViewController methods of viewDidAppear: and viewWillAppear: are actually called BEFORE UIPageViewController's . And then, when you start scrolling, the viewWillAppear: and viewDidAppear: methods are viewWillAppear: , as you might expect for new view controllers.
Here is my structure: I have a BossViewController that contains an OrganizerViewController (actually a couple of different organizers, but that doesn't matter). OrganizerViewController contains a UIPageViewController that contains a series of CustomViewControllers . My code adequately calls the transition methods of the child view in accordance with the apple ( https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html ) for the interaction between the BossViewController and OrganizerViewController (fully functional, absolutely so). The problem lies somewhere between the OrganizerViewController , the child of the UIPageViewController and the first child of the CustomPageViewController .
I tried calling beginAppearanceTransition: and endAppearanceTransition: in the UIPageViewController viewWillAppear: and viewDidAppear: - but this caused the "unbalanced calls" error log to be connected to the console.
Here is the UIPageViewController setup UIPageViewController , all of which are in OrganizerViewController :
- (void)configurePVC { NSDictionary *key = @{UIPageViewControllerOptionInterPageSpacingKey : @([UIScreen mainScreen].bounds.size.width * 0.5)}; _pvc = [[AVSCustomPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:key]; self.pvc.delegate = self; self.pvc.dataSource = self; _pvcArray = [[NSMutableArray alloc] init]; CustomViewController *daily = (CustomViewController *)[self viewControllerAtIndex:6]; self.index = 6; [self.pvcArray addObject:daily]; [self.pvc setViewControllers:self.pvcArray direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil]; [self addChildViewController:self.pvc]; [self.dailyContainerView addSubview:self.pvc.view]; self.pvc.view.frame = self.dailyContainerView.bounds; [self.pvc didMoveToParentViewController:self]; } - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { NSUInteger index = [(CustomViewController *)viewController index]; if (index == 0) { return nil; } index--; return [self viewControllerAtIndex:index]; } - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { NSUInteger index = [(CustomViewController *)viewController index]; if (index == 6) { return nil; } index++; return [self viewControllerAtIndex:index]; } - (UIViewController *)viewControllerAtIndex:(NSUInteger)index { CustomViewController *viewController = [[CustomViewController alloc] init]; viewController.index = index; return viewController; }
source share