How does one ensure that the viewWillAppear:
and viewDidAppear:
(and other view transition methods) are called on a UIPageViewController's
child ViewControllers
?
In my case, the view transition methods are adequately called on all except for the very firstViewController
that the UIPageViewController
opens to. On that firstViewController
, the viewDidAppear:
and viewWillAppear:
methods are actually called BEFORE the UIPageViewController's
view transition methods. And then as one starts scrolling, the viewWillAppear:
and viewDidAppear:
methods are called as one would expect for the new view controllers.
Here is my structure: I have a BossViewController
that contains an OrganizerViewController
(a couple different organizers, actually, but that is irrelevant). The OrganizerViewController
contains a UIPageViewController
, which contains a series of CustomViewControllers
. My code adequately calls the child view transition methods as per apple (https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html) for the interactions between the BossViewController
and the OrganizerViewController
(fully functional, perfectly so). The problem lies somewhere between the OrganizerViewController
, it's child UIPageViewController
, and it's first child CustomPageViewController
.
I have tried calling beginAppearanceTransition:
and endAppearanceTransition: within the UIPageViewController's viewWillAppear:
and viewDidAppear:
- but that resulted in an 'unbalanced calls' error log to console.
Here is the UIPageViewController
set up code, all of which is in the 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;
}