如何确保在viewWillAppear:
子viewDidAppear:
上调用UIPageViewController's
和ViewControllers
(以及其他视图转换方法)?
就我而言,除了firstViewController
打开的UIPageViewController
之外,所有视图转换方法都被充分调用。在firstViewController
上,viewDidAppear:
和viewWillAppear:
方法实际上是在UIPageViewController's
视图转换方法之前调用的。然后当一个人开始滚动时,调用viewWillAppear:
和viewDidAppear:
方法就像人们对新视图控制器所期望的那样。
这是我的结构:我有一个BossViewController
,其中包含OrganizerViewController
(实际上有几个不同的组织者,但这是无关紧要的)。 OrganizerViewController
包含UIPageViewController
,其中包含一系列CustomViewControllers
。我的代码根据apple( https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html )充分调用子视图转换方法,用于BossViewController
和OrganizerViewController
之间的交互(完全正常,完全如此) 。问题出在OrganizerViewController
,它的孩子UIPageViewController
和它的第一个孩子CustomPageViewController
之间。
我尝试在UIPageViewController的beginAppearanceTransition:
和viewWillAppear:
中调用viewDidAppear:
和endAppearanceTransition:但是这导致了一个'不平衡调用'错误日志到控制台。
以下是UIPageViewController
设置代码,所有这些代码都在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;
}