presentModalViewController:Animated is deprecated

2019-01-16 06:11发布

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];
}

5条回答
狗以群分
2楼-- · 2019-01-16 06:49

As Vishal mentioned

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

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

查看更多
爷、活的狠高调
3楼-- · 2019-01-16 06:50
[[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];
查看更多
女痞
4楼-- · 2019-01-16 06:51

Use this line & check:

[self presentViewController:imagePicker animated:YES completion:nil];
查看更多
forever°为你锁心
5楼-- · 2019-01-16 06:55

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];
查看更多
再贱就再见
6楼-- · 2019-01-16 06:56
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
{
    [self presentViewController:objSignupViewController animated:^{} completion:nil];
}
else
{
    [self presentModalViewController:objSignupViewController animated:YES];
}
查看更多
登录 后发表回答