我使用以下代码作为图像选择器。但是当我在模拟器中运行它时,我发生了内存泄漏,并且在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];
}
答案 0 :(得分:210)
使用此行&检查:
[self presentViewController:imagePicker animated:YES completion:nil];
答案 1 :(得分:16)
[[Picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
而不是
[[Picker parentViewControl] dismissModalViewControllerAnimated:YES];
和
[self presentViewController:picker animated:YES completion:nil];
而不是
[self presentModalViewController:picker animated:YES];
答案 2 :(得分:3)
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
{
[self presentViewController:objSignupViewController animated:^{} completion:nil];
}
else
{
[self presentModalViewController:objSignupViewController animated:YES];
}
答案 3 :(得分:3)
正如Vishal所说
[self presentViewController:imagePicker animated:YES completion:nil]; [self dismissViewControllerAnimated:YES completion:nil];
确保您还添加了“完成:nil”
答案 4 :(得分:1)
使用:
[self presentViewController:imagePicker animated:YES completion:nil];
然后为你的解雇模式使用:
[self dismissViewControllerAnimated:controller completion:nil];
或
[self dismissViewControllerAnimated:YES completion:nil];