Search code examples
iosobjective-cpopviewcontrolleranimated

Pop view controller after dismiss


I have a navigation controller A on which i push the view controller B. From B i present modally the view controller C. I need to dismiss C and pop B at the same time. I would like to that in sequence, keeping the dismiss animation first and then the pop animation from B to A. I tried without success this code:

[self dismissViewControllerAnimated:YES completion:^{
       [self.presentingViewController.navigationController popViewControllerAnimated:YES];
}];

Any suggestion on how can i achieve this?


Solution

  • If you are writing in C viewcontoller then :

    UIViewController *pvc = self.presentingViewController;
    UINavigationController *navController = [pvc isKindOfClass:[UINavigationController class]] ? (UINavigationController *)pvc : pvc.navigationController;
    [self dismissViewControllerAnimated:YES completion:^{
      [navController popViewControllerAnimated:YES];
    }];
    

    or if in B view controller

    [self.presentedViewController dismissViewControllerAnimated:YES completion:^{
       [self.navigationController popViewControllerAnimated:YES];
    }];