47675

UIPickerView UIImage and Segue

Question:

In my app, I use the camera with UIImagePickerCollection in my UserView. But once the user, select "use photo" I would like to have my photo in an other view which is "cameraView" because I have some treatment to do with. Here is my code :

-(void)takeAPicture{ NSLog(@"CHEESE"); UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.mediaTypes = @[(NSString *) kUTTypeImage]; imagePicker.allowsEditing = NO; [self presentViewController:imagePicker animated:YES completion:nil]; } -(void)imagePickerController: (UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [self dismissViewControllerAnimated:YES completion:^{ _img = [info objectForKey:UIImagePickerControllerOriginalImage]; if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) { UIImageWriteToSavedPhotosAlbum(_img, nil, nil, nil); }}]; [self performSegueWithIdentifier:@"toCameraView" sender:self]; } -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([[segue identifier] isEqualToString:@"toCameraView"]) { CameraViewController *transferViewController = segue.destinationViewController; transferViewController.img = _img; } }

When i'm running my app, I receive an warning message which is :

Warning: Attempt to present <CameraViewController: 0x17e20eb0> on <EIUserViewController: 0x189b1000> while a presentation is in progress!

I don't understand what it is, and how to deal with it, I can't manage to receive my image in the other view and showing my view directly after choosing "use picture". If someone has an explanation or a solution ? thank you guys !

Answer1:

You are trying to [self performSegueWithIdentifier:@"toCameraView" sender:self] during UIImagePickerController dismissing, other words: cannot animate second VC appearing during first VC disappearing. Try to move [self performSegueWithIdentifier:@"toCameraView" sender:self]; inside completionBlock:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [self dismissViewControllerAnimated:YES completion:^{ _img = [info objectForKey:UIImagePickerControllerOriginalImage]; if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) { UIImageWriteToSavedPhotosAlbum(_img, nil, nil, nil); [self performSegueWithIdentifier:@"toCameraView" sender:self]; }}]; }

Answer2:

So, when the imagePicker calls the delegate method imagePickerController: didFinishPickingMediaWithInfo: the imagePicker is still being presented by your viewController.

One solution to this would be presenting the cameraView when you come back to your viewController like so:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [self dismissViewControllerAnimated:YES completion:^{ _img = [info objectForKey:UIImagePickerControllerOriginalImage]; if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) { UIImageWriteToSavedPhotosAlbum(_img, nil, nil, nil); }}]; self.newPicture = YES; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if (self.newPicture) { [self performSegueWithIdentifier:@"toCameraView" sender:self]; self.newPicture = NO; } }

Hope it helps

Recommend

  • Image getting stretched
  • Winform GUI not showing up in WinPE
  • Expand a Cell to Show Sub Categories
  • mapping of JSON keys with leading “@” with restkit
  • Can I manipulate FDatasnapshot once I have queried for it?
  • How do you delete rows from UITableView?
  • block execution iOS and assigning variable
  • Unable to send Multipart-Form data with AFNetworking 3.0
  • Share Facebook User ID between more than one application
  • How to check for a badge number on app launch on iPhone
  • Building for iOS if registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later
  • IOS : com.facebook.sdk error 5
  • NSUserDefaults standardUserDefaults setObject: forKey: not working for Multivalue preference
  • Payumoney getway error occur in ios
  • Is Cocoa's NSMutableArray sparse?
  • Why does adding my viewcontroller to a navigationcontroller seem to interfere with my constraints?
  • Storing access token and refresh token in KeyChain
  • Getting information from a NSDictionary
  • How to create sharable Core Data .sqlite backups locally and in iCloud using current NSPersistentSto
  • Why does my batch script fail to execute when run as administrator?
  • Swift POST Request in same Thread
  • iOS how to store a NSDictionary or JSON in a file's xattr?
  • Xcode6 - Autolayout view in an other autolayout view
  • UserDefaults between Objective-C and Swift
  • Post on Facebook Page from iOS App Not Showing Up on Page?
  • complex JSON parsing using Objective-C
  • How to convert a File Blob to NSData?
  • Using iPhone as iBeacon Transmitter
  • How to observe the value of an NSTextField
  • objective c when to use NSDictionary instead of NSArray [duplicate]
  • Swipe Buttons in IOS 9 Remote Notification - Work when app in background not when app out of memory
  • 'Terminating app due to uncaught exception'.. it couldn't find MainWindow, which no l
  • NSDate isMemberOfClass: [NSDate class] returns false? [duplicate]
  • How to execute two asynchronous functions sequentially
  • Checking launchOptions in Swift 3
  • UICollectionview scroll horizontal and vertical
  • Encoding issue with ASIHttpRequest
  • didUpdatePushCredentials not get called
  • Build Successful but not running on simulator
  • How to change the font size of a single index for UISegmentedControl?