I am trying to create a modal view controller after picking an image from the image picker. I use the code :
- (void)imagePickerController:(UIImagePickerController *)picker1 didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *img = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[myPicker dismissViewControllerAnimated:YES ];
myImagePicker = [[ImagePickerViewController alloc] initWithNibName:@"ImagePickerViewController" bundle:nil];
myImagePicker.modalTransitionStyle =
UIModalTransitionStyleCrossDissolve;
[self presentViewController:myImagePicker animated:YES completion:nil];
}
I receive the warning:
Warning: Attempt to Present <Modal View Controller: 0x7561600> on <ViewController: 0x75a72e0 > while a presentation is in progress!
and the modal view does not appear.
Here the issue is happening because, we are first dismissing the
UIImagePicker
and immediately we are displaying another view as modal view. That's why we are getting this error.
So, the solution is the method with the completion handler.
- (void)imagePickerController:(UIImagePickerController *)picker1 didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *img = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[self dismissViewControllerAnimated:YES completion:^{
myImagePicker = [[ImagePickerViewController alloc] initWithNibName:@"ImagePickerViewController" bundle:nil];
myImagePicker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:myImagePicker animated:YES completion:nil];
}];
}
No comments:
Post a Comment