Reputation:
I'm trying to make my app switch to another view when the user finish selecting an image, but what happen is when the user finish picking the image, it dismisses the picker and comes back to the same view.
Here's my code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
DrawingViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Drawing"];
viewController.image.image = image;
[self presentModalViewController:viewController animated:NO];
}
Upvotes: 2
Views: 1994
Reputation: 4057
That happens because you're dismissing the picker modal view controller with animation and presenting the new view controller right away. You can only present a new modal view controller after the previous one has been dismissed. A solution would be to dismiss the picker modal without animation :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:NO];
DrawingViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Drawing"];
viewController.image.image = image;
[self presentModalViewController:viewController animated:NO];
}
Another solution (that works only on iOS 5) is to use the dismissViewControllerAnimated: completion:
method :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissViewControllerAnimated:YES completion:^(){
DrawingViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Drawing"];
viewController.image.image = image;
[self presentModalViewController:viewController animated:NO];
}];
}
Upvotes: 6