-1

code dans A_UIViewController:A_UIViewController presentViewController B_UIViewController presentViewController UIImagePickerController rejette A_UIViewController

PrestBViewController *aviewcontroller = [[PrestBViewController alloc] init]; 
[self presentViewController:aviewcontroller animated:YES completion:nil]; 

code dans B_UIViewController:

-(void)presentAction { 
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 
    imagePickerController.delegate = (id)self; 
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 
    [self presentViewController:imagePickerController animated:YES completion:nil]; 
} 

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    [picker.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 
} 

Quand je lance le code, il se bloque à:

[picker.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 

Can quelqu'un vous aide?

+0

et que dit l'accident? – Joshua

+0

Ajoutez votre journal des erreurs –

Répondre

0

code dans A_viewcontroller

- (IBAction)PresentAction:(id)sender { 
    B_ViewController *aviewcontroller = [self.storyboard instantiateViewControllerWithIdentifier:@"aa"]; 
    [self presentViewController:aviewcontroller animated:YES completion:nil]; 
} 
code

dans B_viewController

@implementation ViewController{ 
    UIImagePickerController *picker; 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; //Check if Camera Available 
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 

     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error" message:@"Device has no Camera" preferredStyle:UIAlertControllerStyleAlert]; 

     UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; 
     [alertController addAction:ok]; 

     [self presentViewController:alertController animated:YES completion:nil]; 
    } 



- (IBAction)takePic:(id)sender { //Button to get image from camera 
    picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.allowsEditing = YES; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    [self presentViewController:picker animated:YES completion:NULL]; 
} 

- (IBAction)chooosePic:(id)sender { //Button to get image from albums 
    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.allowsEditing = YES; 
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    [self presentViewController:picker animated:YES completion:NULL]; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { //Choose image 
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; 
    self.imageView.image = chosenImage; 
    [picker dismissViewControllerAnimated:YES completion:NULL]; 
} 
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { //if cancelled before selection 
    [picker dismissViewControllerAnimated:YES completion:NULL]; 
} 

Works fine Essayez