presentModalViewController:动画在iOS6的弃用(presentModal

2019-08-20 05:31发布

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

Answer 1:

使用此行并检查:

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


Answer 2:

[[Picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];

代替

 [[Picker parentViewControl] dismissModalViewControllerAnimated:YES];

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

代替

[self presentModalViewController:picker animated:YES];


Answer 3:

作为维沙尔提到

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

请确保您已经添加“完成:无”以及



Answer 4:

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


Answer 5:

使用:

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

然后你被解雇模态的使用:

[self dismissViewControllerAnimated:controller completion:nil];

要么

[self dismissViewControllerAnimated:YES completion:nil];


文章来源: presentModalViewController:Animated is deprecated in ios6