Peter Warbo
Peter Warbo

Reputation: 11718

dismissViewControllerAnimated completion block is not called

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];

Upvotes: 10

Views: 11090

Answers (2)

Peter Warbo
Peter Warbo

Reputation: 11718

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()

Upvotes: 1

Andrea
Andrea

Reputation: 26383

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.

Upvotes: 0

Related Questions