presentModalViewController:Animated已在ios6中弃用

我正在使用下面的代码图像select器。 但是当我在模拟器中运行它,我有一个内存泄漏,我得到一个关于presentModalViewcontroller:animated的警告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]; } 

  • 设置UIImagePickerController“移动和缩放”裁剪框的尺寸
  • UIImagePickerController错误:快照未呈现的视图会导致iOS 7中的空快照
  • UIImagePickerController不在iOS 8中呈现
  • 使用UIImagePickerController时,iOS 10错误 <私人>
  • UIImage在iPhone上用文件名保存图像
  • didFinishPickingMediaWithInfo返回零照片
  • iOS 8快照未呈现的视图会导致一个空的快照
  • iOS 8 SDK:模态UIWebView和相机/图像select器
  • 5 Solutions collect form web for “presentModalViewController:Animated已在ios6中弃用”

    使用这一行和检查:

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

    代替

      [[Picker parentViewControl] dismissModalViewControllerAnimated:YES]; 

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

    代替

     [self presentModalViewController:picker animated:YES]; 

    维沙尔提到

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

    确保你添加了“completion:nil”

     if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) { [self presentViewController:objSignupViewController animated:^{} completion:nil]; } else { [self presentModalViewController:objSignupViewController animated:YES]; } 

    使用:

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

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

     [self dismissViewControllerAnimated:controller completion:nil]; 

    要么

     [self dismissViewControllerAnimated:YES completion:nil];