101

我将以下代码用于图像选择器。但是当我在模拟器中运行它时,我遇到了内存泄漏,并且我收到了关于presentModalViewcontroller:animated在 iOS6 中被弃用的警告。我也被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];
}
4

5 回答 5

218

使用此行并检查:

[self presentViewController:imagePicker animated:YES completion:nil];
于 2013-04-08T08:03:00.097 回答
17
[[Picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];

代替

 [[Picker parentViewControl] dismissModalViewControllerAnimated:YES];

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

代替

[self presentModalViewController:picker animated:YES];
于 2013-04-08T08:06:12.663 回答
4
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
{
    [self presentViewController:objSignupViewController animated:^{} completion:nil];
}
else
{
    [self presentModalViewController:objSignupViewController animated:YES];
}
于 2013-11-29T11:29:51.803 回答
4

正如维沙尔所说

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

确保你也添加了“completion:nil”

于 2014-01-19T09:18:58.370 回答
2

采用:

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

然后为您的解雇模式使用:

[self dismissViewControllerAnimated:controller completion:nil];

或者

[self dismissViewControllerAnimated:YES completion:nil];
于 2015-08-01T08:14:06.653 回答