Reputation: 3753
I am modally presenting a ViewController from another one. The completion block is being called immediately, while the presented VC is still presented. Why would that be? Code follows.
UIStoryboard* sb = [UIStoryboard storyboardWithName:...];
UINavigationController* nc = [sb instantiateViewController...];
nc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:nc
animated:YES
completion:^{ /* Called immediately! */ }];
There is stuff I want to do only when the presented VC is finished. I have a workaround but my understanding is I should be able to do it in the completion block.
Upvotes: 1
Views: 2621
Reputation: 3753
OK I had RTFM and saw this: "completion: The block to execute after the presentation finishes." Which really does imply what I thought. Ambiguous at best.
HOWEVER... elsewhere we read "The completion handler is called after the viewDidAppear: method is called on the presented view controller." Which is quite another thing, and confirms Ian.
So my workaround is actually the right way to do it...
Upvotes: 0
Reputation: 2045
The completion block is called once the viewController has been presented, as per Apple's documentation. This is the intended behavior: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/presentViewController:animated:completion:
I'd suggest wiring up some sort of callback in your viewController's viewWillDissappear to perform an action if necessary.
Upvotes: 0