PresmodalViewController: 在 ios6中不推荐使用动画

我使用下面的代码为一个图像选择器。但是当我在模拟器中运行它时,我有一个内存泄漏,并且我得到一个关于在 iOS6中弃用 presentModalViewcontroller:animated的警告。我也得到 dismissModalViewController:animated弃用。我用的是 SDK 6.1。

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];
}
73079 次浏览

Use this line & check:

[self presentViewController:imagePicker animated:YES completion:nil];
[[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];
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
{
[self presentViewController:objSignupViewController animated:^{} completion:nil];
}
else
{
[self presentModalViewController:objSignupViewController animated:YES];
}

As Vishal mentioned

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

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

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