Dismiss Modalview after imagePickerController:didFinishPickingMediaWithInfo:
-
21-06-2021 - |
Question
I have a ViewController (VC1) that opens another ViewController (VC2) modally that is embedded in a NavigationController (NavC1). VC2 is used as a source selection view for the user to select different sources, such as the built-in photo library. When the user selects the photo library in VC2 I am opening Apple's imagePicker.
VC1 --(modal)--> NavC1 ----> VC2
In the imagePickerdidFinish I would like to close the before modally presented VC2. Actually this method looks as follows.
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
...
NSError* error;
if([UIImageJPEGRepresentation(image, 0.5) writeToFile:path options:NSDataWritingFileProtectionComplete error:&error] == NO)
{
NSLog(@"Saving image to file failed with error %@",[error localizedDescription]);
}
picker.delegate = nil;
[self dismissModalViewControllerAnimated:YES];
...
}
What I have tried so far:
- I have tried to dismiss it using the parent navigation controller
- I have stored a reference to VC2 in
prepareForSegue:
of VC1 and passed a delegate back to VC1 from VC2 when the imagePicker did finish. In this method I have tried to simply dimiss the modal view manually ([self.myModalView dismissModalViewControllerAnimated:YES]
)
Does anyone have a suggestion for me? Thanks in advance!
No correct solution
OTHER TIPS
If you are coming to VC2 by [self.navigationController PushViewController:VC2Object animated:YES];
then you need to pop it i.e [self.navigationController popViewController];
If you are coming to VC2 by [self.navigationController presentedViewController];
then you need to [self dismissModalViewControllerAnimated:YES];
Therefore, check how you are loading VC2 viewController in memory.