Let's say, I have an instance of a view controller class called VC2. In VC2, there is a "cancel" button that will dismiss itself. But I can't detect or receive any callback when the "cancel" button got trigger. VC2 is a black box.
A view controller (called VC1) will present VC2 using presentViewController:animated:completion:
method.
What options does VC1 have to detect when VC2 was dismissed?
Edit: From the comment of @rory mckinnel and answer of @NicolasMiari, I tried the following:
In VC2:
-(void)cancelButton:(id)sender
{
[self dismissViewControllerAnimated:YES completion:^{
}];
// [super dismissViewControllerAnimated:YES completion:^{
//
// }];
}
In VC1:
//-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
- (void)dismissViewControllerAnimated:(BOOL)flag
completion:(void (^ _Nullable)(void))completion
{
NSLog(@"%s ", __PRETTY_FUNCTION__);
[super dismissViewControllerAnimated:flag completion:completion];
// [self dismissViewControllerAnimated:YES completion:^{
//
// }];
}
But the dismissViewControllerAnimated
in the VC1 was not getting called.
dismissViewControllerAnimated
in your VC1 controller I believe it will get called when you hit cancel on VC2. Detect the dismiss and then call the super classes version which will do the actual dismiss. – Rory McKinnel[self.presentingViewController dismissViewControllerAnimated]
. It may be that the inner code has a different mechanism for asking the presenter to do the dismiss. – Rory McKinnel