10
votes

I'm trying to dismiss a view controller like this:

[composeViewController dismissViewControllerAnimated:YES completion:^{

    NSLog(@"Hello"); // Never outputted
}];

The view controller is dismissed, but for some reason the completion block is never called.

I have never had any issues with completion block not being called with other view controllers.

This view controller is "special" though, because it's added as a child view controller (which I have not worked with previously in my app). Does this impose any side effects why the completion block is not called?

It's added like this:

UIViewController *rootVC = [UIApplication sharedApplication].delegate.window.rootViewController;
[rootVC addChildViewController:self];
[rootVC.view addSubview:self.view];
[self didMoveToParentViewController:rootVC];
2
addChildViewController: actually pushes that view controller onto the navigation stack. You have to pop it off before that block can fireCodaFi
I tried doing [composeViewController removeFromParentViewController]; (I can see that it's removed from childViewControllers property of rootViewController) before calling dismiss... but the completion block is still not called.Peter Warbo
po the navigation stack, then.CodaFi
Why don't you present it using -presentViewController... ? the dismiss method is paired with this one. Or do everything manually. Whrn you present a VC there are lot of properties set in the container: presentingViewController, presentedViewController etc... if you do manually you won't have them valorizedAndrea
@Andrea I usually use -presentViewController... but this view controller I'm using is from an external source so I don't have any control over how they want it to be presented.Peter Warbo

2 Answers

1
votes

Found out what the issue was: the 3rd party view controller I was using had overridden - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion without actually calling completion()

0
votes

If you present a modal, is the view controller that receive the message (or the top in hierarchy , I still didn't get that) that handles all the process of adding the child v.c. swapping view etc. It seems that you are doing a mix of the two techniques. Just use one.
So present it using - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion ad dismiss it using dismissViewController let the view controller manages everything.