UIPageViewController Child的viewWillAppear:& viewDidAppear:转换调用

时间:2016-07-21 17:43:03

标签: ios objective-c uipageviewcontroller transitions

如何确保在viewWillAppear:viewDidAppear:上调用UIPageViewController'sViewControllers(以及其他视图转换方法)?

就我而言,除了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 )充分调用子视图转换方法,用于BossViewControllerOrganizerViewController之间的交互(完全正常,完全如此) 。问题出在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;
}

0 个答案:

没有答案