Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

presentModalViewController:Animated is deprecated in ios6

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];
}
like image 836
Ram Avatar asked Apr 08 '13 08:04

Ram


4 Answers

Use this line & check:

[self presentViewController:imagePicker animated:YES completion:nil];
like image 93
Vishal Avatar answered Oct 10 '22 23:10

Vishal


[[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];
like image 34
deepesh Avatar answered Oct 10 '22 23:10

deepesh


As Vishal mentioned

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

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

like image 4
Krishna Sapkota Avatar answered Oct 11 '22 00:10

Krishna Sapkota


if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
{
    [self presentViewController:objSignupViewController animated:^{} completion:nil];
}
else
{
    [self presentModalViewController:objSignupViewController animated:YES];
}
like image 4
Mohit Avatar answered Oct 10 '22 23:10

Mohit