Search code examples
iosios6uiviewcontroller

iOS 6 Custom Container View Controller


I have a custom view container that use the following code to dismiss the current viewController and present the previous one...

- (void)popToViewControllerwithAnimation:(AnimationStyle)animation
{
    if(self.currentChildIndex == 0)
        return;

    UIViewController *currentChildController = self.childViewControllers[self.currentChildIndex];

    self.currentChildIndex--;

    UIViewController *previousChildController = self.childViewControllers[self.currentChildIndex];

    if(animation == kSlideRight || animation == kSlideDown) {

        CGRect onScreenFrame = self.view.bounds;

        CGRect offScreenFrame = self.view.bounds;

        CGFloat duration = 0.35;

        if(animation == kSlideRight) {

            offScreenFrame.origin.x += offScreenFrame.size.width;

            duration = 0.3;
        }

        if(animation == kSlideDown)
            offScreenFrame.origin.y += offScreenFrame.size.height;

        [currentChildController willMoveToParentViewController:nil];

        [self addChildViewController:previousChildController];

        [UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{

        currentChildController.view.frame = offScreenFrame;

        previousChildController.view.transform = CGAffineTransformIdentity;

        previousChildController.view.frame = onScreenFrame;

        } completion:^(BOOL finished) {

            [currentChildController.view removeFromSuperview];

            [currentChildController removeFromParentViewController];

            [previousChildController didMoveToParentViewController:self];

        }];

    }
}

All is working fine except the previousViewController appearance methods never get called...

Any suggestions?


Solution

  • You never add previousChildController.view to self.view.