presentModalViewController:Animated is deprecated

2019-01-16 06:28发布

问题:

I am using the following code for an image picker. But when I run it in the simulator, I have a memory leak and I get a warning about presentModalViewcontroller:animated being deprecated in iOS6. I also get dismissModalViewController:animated deprecated. I'm using the SDK 6.1.

Code for ImagePicker:

- (void)showAlbum:(id)sender { 
    imagePicker=[[UIImagePickerController alloc]init];
    imagePicker.delegate = self;
    imagePicker.allowsEditing =NO;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:imagePicker animated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    //release picker
    [picker dismissModalViewControllerAnimated:YES];
}

回答1:

Use this line & check:

[self presentViewController:imagePicker animated:YES completion:nil];


回答2:

[[Picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];

Instead of

 [[Picker parentViewControl] dismissModalViewControllerAnimated:YES];

and

[self presentViewController:picker animated:YES completion:nil];

Instead of

[self presentModalViewController:picker animated:YES];


回答3:

As Vishal mentioned

[self presentViewController:imagePicker animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];

make sure you have added "completion:nil" as well



回答4:

if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
{
    [self presentViewController:objSignupViewController animated:^{} completion:nil];
}
else
{
    [self presentModalViewController:objSignupViewController animated:YES];
}


回答5:

Use:

[self presentViewController:imagePicker animated:YES completion:nil];

And then for your dismissal modal use:

[self dismissViewControllerAnimated:controller completion:nil];

or

[self dismissViewControllerAnimated:YES completion:nil];